django cloudinary通过url上传远程图像 - 文件名无效

时间:2012-10-18 06:00:47

标签: django python-2.7 cloudinary

我正在尝试上传托管在第三方服务器上的图片。这是我正在使用的代码:

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)

我收到以下错误:

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

我不确定我做错了什么 - 你能帮忙吗?

感谢。

1 个答案:

答案 0 :(得分:1)

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

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

感谢您报告此事。