3
votes

Hi I tried to upload files to Google drive using following code

def upload_file(self,file_name,path):

    parents = None
    if not path == None:
        parents = self.create_path(path)
    mime_type = self.get_mime_type_for(file_name)
    file_id = self.check_file_exist(file_name,parents,mime_type)
    if file_id == None:

        print "creating file...........",file_name                      
        print "mime_type",mime_type
        media = MediaFileUpload(file_name, mimetype=mime_type, resumable=True)
        body = {
            'title': file_name,
            'description': 'A test document',
            'mimeType': mime_type
        }
        if not parents == None:
            body['parents'] = [{'id': parents}]
        f = self.drive_service.files().insert(body=body, media_body=media).execute()
    else:
        print "file exists........... updating"
        self.update_file(file_id, file_name)

this code works for smaller files (tested up to 25MB). But if i tried to upload large files(70MB) the system gives the error message

Traceback (most recent call last):

File "googledrive.py", line 176, in

gd.upload_file("test.mp4","/media/media")

File "googledrive.py", line 122, in upload_file

f = self.drive_service.files().insert(body=body, media_body=media).execute()

File "/usr/local/lib/python2.7/dist-packages/oauth2client/util.py", line 132, in positional_wrapper

return wrapped(*args, **kwargs)

File "/usr/local/lib/python2.7/dist-packages/apiclient/http.py", line 688, in execute

_, body = self.next_chunk(http=http, num_retries=num_retries)

File "/usr/local/lib/python2.7/dist-packages/oauth2client/util.py", line 132, in positional_wrapper

return wrapped(*args, **kwargs)

File "/usr/local/lib/python2.7/dist-packages/apiclient/http.py", line 867, in next_chunk

headers=headers)

File "/usr/local/lib/python2.7/dist-packages/oauth2client/util.py", line 132, in positional_wrapper

return wrapped(*args, **kwargs)

File "/usr/local/lib/python2.7/dist-packages/oauth2client/client.py", line 490, in new_request

redirections, connection_type)

File "/usr/local/lib/python2.7/dist-packages/httplib2/init.py", line 1570, in request

(response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey)

File "/usr/local/lib/python2.7/dist-packages/httplib2/init.py", line 1317, in _request

(response, content) = self._conn_request(conn, request_uri, method, body, headers)

File "/usr/local/lib/python2.7/dist-packages/httplib2/init.py", line 1286, in _conn_request

response = conn.getresponse()

File "/usr/lib/python2.7/httplib.py", line 1045, in getresponse

response.begin()

File "/usr/lib/python2.7/httplib.py", line 409, in begin

version, status, reason = self._read_status()

File "/usr/lib/python2.7/httplib.py", line 373, in _read_status

raise BadStatusLine(line)

httplib.BadStatusLine: ''
1
How long until it fails? might be relevant: code.google.com/p/google-api-python-client/issues/detail?id=231 According to the docs, it should have a max of 10 gigs.vroomfondel

1 Answers

2
votes

If your upload is taking longer than about an hour, your token might expire and your download will fail. This is a known issue.

Also, see Google Mirror API throwing BadStatusLine exception (Python)