如何将Django中的InMemoryUploadedFile转换为flickr API的fomat? [英] How to convert an InMemoryUploadedFile in django to a fomat for flickr API?
问题描述
我有一堂课,可以将文件上传到Flickr.该文件的类型为
"InMemoryUploadedFile".
I have a class that uploads a file to Flickr. The file is of type
'InMemoryUploadedFile'.
我想知道如何将'InMemoryUploadedFile'文件中的数据转换或传递为flickr的API格式?
I would like to know how to convert or pass the data in the 'InMemoryUploadedFile' file, to a format for flickr's API?
例如:
{'photo': ('image.jpg', <InMemoryUploadedFile: image.jpg (image/jpeg)>)}
上传API: https://www.flickr.com/services/api /upload.api.html
错误代码
<?xml version="1.0" encoding="utf-8" ?>
<rsp stat="fail">
<err code="4" msg="Filesize was zero" />
</rsp>
推荐答案
InMemoryUploadedFile
is a wrapper around a file object. You can access the file object using the file
attribute. So, in your example, try passing this to the Flickr API:
{'photo': my_in_memory_file.file}
如果这行不通,请围绕提交请求所使用的代码详细编辑您的问题.
If that doesn't work, please edit your question with more detail around the code you're using to submit the request.
这篇关于如何将Django中的InMemoryUploadedFile转换为flickr API的fomat?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!