Empty file exception when uploading via Django Rest Frameowk
I have a Django model with an ImageFileField attribute. I have successfully uploaded images using the Django admin and had those images uploaded to Cloudinary, using this setting in my Django settings.py file.
DEFAULT_FILE_STORAGE = 'cloudinary_storage.storage.MediaCloudinaryStorage'
def update_menu_item_picture_from_url(self, menu_item, url):
with NamedTemporaryFile(delete=False) as img_temp:
print (img_temp.name)
img_temp.write(urlopen(url).read())
img_temp.flush()
menu_item.picture.save(f"{menu_item.name}.jpg", img_temp)
File "/home/ryan/recipes/lib/python3.6/site-packages/django/core/files/storage.py", line 52, in save
return self._save(name, content)
File "/home/ryan/recipes/lib/python3.6/site-packages/cloudinary_storage/storage.py", line 68, in _save
response = self._upload(name, content)
File "/home/ryan/recipes/lib/python3.6/site-packages/cloudinary_storage/storage.py", line 62, in _upload
return cloudinary.uploader.upload(content, **options)
File "/home/ryan/recipes/lib/python3.6/site-packages/cloudinary/uploader.py", line 46, in upload
return call_cacheable_api("upload", params, file=file, **options)
File "/home/ryan/recipes/lib/python3.6/site-packages/cloudinary/uploader.py", line 341, in call_cacheable_api
result = call_api(action, params, http_headers, return_error, unsigned, file, timeout, **options)
File "/home/ryan/recipes/lib/python3.6/site-packages/cloudinary/uploader.py", line 421, in call_api
raise Error(result["error"]["message"])
cloudinary.exceptions.Error: Empty file
-
Hi Ryan,
Would you kindly create a ticket providing your cloud name so I can investigate further?
Regards,
Mo
0 -
I have created ticket #140365 that references this issue.
Thanks!
Ryan
0 -
Hi there,
I am facing exactly the same problem with Django, and I use the same methodology - I create a temporary file, write it on disk, and save to the ImageField. If I work locally - all works fine, but as soon as I turn on CloudinaryStorage I get the same error message that file is empty.
Is there any update on this topic?
Regards,
Slawa
0
Post is closed for comments.
Comments
3 comments