2017-01-18 116 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。我發現它更好用。

相關問題