Reputation: 3
I have a Python script that try to upload files on google storage but keeps appearing this error:
googleapiclient.errors.UnknownFileType:
Here is my code:
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
is an audio .raw file.
The libraries I am using are:
from oauth2client.client import GoogleCredentials
from googleapiclient.discovery import build
from google.cloud import storage
Upvotes: 0
Views: 453
Reputation: 38369
I believe that, because your file ends in ".raw", the "mimetypes" library is having trouble guessing the content type you want for the object. Try explicitly specifying the "media_mime_type" keyword argument with the MIME type you want GCS to use.
This is where I think the error is likely being generated: https://github.com/google/google-api-python-client/blob/master/googleapiclient/discovery.py#L789
Also, may I suggest that you take a look at the Google Cloud Client Library for Python. I found it nicer to use.
Upvotes: 1