关于python 2.7:django cloudinary通过url上传远程图像-文件名无效

django cloudinary upload remote image via url - invalid file name

我正在尝试上载托管在第三方服务器上的图像。下面是我使用的代码:

def saveedit(请求):

1
2
3
4
5
6
7
8
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)

我得到以下错误:

1
2
3
4
5
6
7
8
9
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

我不知道我做错了什么-你能帮忙吗?

谢谢。


这里的问题是,从请求接收到的图像参数实际上是unicode类型,而不是str类型。Cloudinary的python库的当前版本不能正确处理这一问题。该库的下一个版本将包含此问题的修复程序。同时,您可以执行以下操作:

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

感谢您报告。