0
votes

I am trying to upload an image hosted on a third party server. Here is the code I am using:

def saveEdit(request):

image = request.REQUEST.get('image','')
title = request.REQUEST.get('title','')
type = request.REQUEST.get('type','')
state = request.REQUEST.get('state','')

cimage = cloudinary.uploader.upload(image, public_id = 'img_'+request.user.__str__()+"_"+title, format='jpg')

return HttpResponse('Got '+image + " type: "+type + " state: "+state + " title:"+request.user.__str__() + "_"+title + " uploaded "+cimage.image.url)

I get the following error:

Invalid image file

Request Method: GET
Request URL:    http://127.0.0.1:8000/saveEdit?image=http://app2.pixlr.com/_temp/507f95e1ec8d8337e5000002.jpg&type=jpg&state=copy&title=13838
Django Version: 1.4.1
Exception Type: Exception
Exception Value:    
Invalid image file
Exception Location: /Library/Python/2.7/site-packages/cloudinary/uploader.py in call_api, line 155

I am not sure what I am doing wrong - can you help?

Thanks.

1
It could be that the upload method is expecting an image, when you are passing it a URL?Burhan Khalid

1 Answers

1
votes

The issue here is that the image parameter as received from the request is actually of type unicode and not str. The current version of Cloudinary's python library does not handle this correctly. The next version of the the library will include a fix for this issue. In the meanwhile, you can do the following:

cimage = cloudinary.uploader.upload(image.encode('utf-8'), public_id = 'img_'+request.user.__str__()+"_"+title, format='jpg')

Thank you for reporting this.