Cloudinary 图片从 django 上传
Cloudinary Image upload from django
我正在尝试上传 image/file 到 clodinary 以取回 url 使用此代码
medical_file = request.FILES['medical_file']
out = cloudinary.uploader.upload(File.open(medical_file, "rb"))
url = out['url']
medical_file_url = url
而且我也成功获得了 url(我已经在我的控制台上打印了)
但后来我收到以下错误:cloudinary.api.Error: Empty file
根据 Cloudinary 的 documentation:
In cases where images are uploaded by users of your Django application through a web form, you can pass the parameter of your Django's request.FILES to the upload method
因此,在您的情况下,您可以通过将 request.FILES['medical_file']
直接传递给上传方法来在服务器端上传文件:
out = cloudinary.uploader.upload(request.FILES['medical_file'])
我正在尝试上传 image/file 到 clodinary 以取回 url 使用此代码
medical_file = request.FILES['medical_file']
out = cloudinary.uploader.upload(File.open(medical_file, "rb"))
url = out['url']
medical_file_url = url
而且我也成功获得了 url(我已经在我的控制台上打印了)
但后来我收到以下错误:cloudinary.api.Error: Empty file
根据 Cloudinary 的 documentation:
In cases where images are uploaded by users of your Django application through a web form, you can pass the parameter of your Django's request.FILES to the upload method
因此,在您的情况下,您可以通过将 request.FILES['medical_file']
直接传递给上传方法来在服务器端上传文件:
out = cloudinary.uploader.upload(request.FILES['medical_file'])