我可以使用服务对象将文件上传到Google云端存储吗?例如:
from apiclient import discovery
from oauth2client.client import GoogleCredentials
credentials = GoogleCredentials.get_application_default()
service = discovery.build('storage', 'v1', credentials=credentials)
request = service.objects().insert(
bucket='MY_BUCKET',
name='test.jpg',
body={'contentType': self.request.POST.get('image').type},
media_body=self.request.POST.get('image')
)
response = request.execute()
它抛出错误:
HttpError:https://www.googleapis.com/storage/v1/b/MY_BUCKET/o ?alt = json& name = test.jpg返回“上传请求必须包含uploadType网址参数和以...开头的网址路径/上传/“>
我可以将缺失的路径和参数传递给discovery.build吗?