2017-01-18 69 views
0

我有一个Python脚本,尝试上载的谷歌存储的文件,但继续出现此错误:上传.RAW文件到谷歌云存储

googleapiclient.errors.UnknownFileType:

这里是我的代码:

def create_service(): 

    credentials = GoogleCredentials.get_application_default() 

    return build('storage', 'v1', credentials=credentials) 

service=create_service() 

request=service.objects().insert(bucket='testBucket',name='test.raw',media_body=path_files+file_raw) 

response=request.execute() 

exit() 

file_raw是一个音频.raw文件。

我使用的库是:

from oauth2client.client import GoogleCredentials 

from googleapiclient.discovery import build 

from google.cloud import storage 
+0

你好,你可以为你的代码添加一个更好的缩进,并指定哪些库用于在谷歌存储上上传? –

回答

1

我相信,因为您的文件在“.RAW”结束时,‘MIME类型’库中是有问题的猜测你想要的对象的内容类型。尝试使用您希望GCS使用的MIME类型明确指定“media_mime_type”关键字参数。

这是我认为很可能正在生成错误:https://github.com/google/google-api-python-client/blob/master/googleapiclient/discovery.py#L789

而且,我可以建议你看一看的Google Cloud Client Library for Python。我发现它更好用。

相关问题