2024-10-06 11:21:36 发布
网友
用django将文件发送到Google云存储的最佳方式是什么。在
现在我用post方法获取文件
file = request.FILES['image']
但当我试着去GCS的时候
我得到了这个错误InMemoryUploadedFile,所以我必须将文件保存在一个临时文件中,然后发送到GCS,但是速度很慢。在
InMemoryUploadedFile
错误可能是由于文件名和文件名的错误使用。尝试使用上载请求同步文件流,如下所示:
from google.cloud import storage def upload_file(file,projectName,bucketName, fileName, content_type): client = storage.Client(projectName) bucket = client.get_bucket(bucketName) blob = bucket.blob(fileName) blob.upload_from_string( file, content_type=content_type) url = blob.public_url if isinstance(url, six.binary_type): url = url.decode('utf-8') return url
进一步阅读,Reference.
错误可能是由于文件名和文件名的错误使用。尝试使用上载请求同步文件流,如下所示:
进一步阅读,Reference.
相关问题 更多 >
编程相关推荐