Google Drive API: Uploading & Downloading Files




About this tutorial:

Video duration: 12:13
In a short dozen minutes, Google engineer Wesley Chun guides you through this jam-packed episode featuring an introduction to the new Drive API (v3), an interview with a Google Drive engineer about the API design, and a code walkthrough of real source code you can use today! This time, it’s a command-line script that performs Drive file uploads & downloads, presented first in the original API (v2) followed by a how-to segment on migrating it step-by-step to the new API (v3). In addition, the uploading segment includes the option of converting to Google Apps formats while the download…

Post Author: OfficeTutes.com

Apple lover, ICT and LEAN consultant, MS Office lecturer My other website with video tutorials - Tutorials, guides and news for iPhones and iPads

21 thoughts on “Google Drive API: Uploading & Downloading Files

    Akshatha Laxmi

    (August 6, 2019 - 2:04 am)

    I copied the exact same code but I was getting the following error:
    raise HttpError(resp, content, uri=self.uri)

    googleapiclient.errors.HttpError: <HttpError 403 when requesting https://www.googleapis.com/upload/drive/v3/files?alt=json&uploadType=multipart returned "Insufficient Permission: Request had insufficient authentication scopes.">

    What should I do to fix it?

    Iwan Krisnawan

    (August 6, 2019 - 2:04 am)

    hey bro, do you know how to add caption track video (vtt) on google drive with coding ?

    Ghundi

    (August 6, 2019 - 2:04 am)

    Can you tell me whats the content of storage.json ???

    Legnahar Prime

    (August 6, 2019 - 2:04 am)

    Is it possible to do smth like this in C++ ?

    Why php download code
    Fatal error: Uncaught exception 'Google_Service_Exception' with message '{

    "error": {

    "errors": [

    {

    "domain": "global",

    "reason": "fileNotExportable",

    "message": "Export only supports Google Docs."

    }

    ],

    "code": 403,

    "message": "Export only supports Google Docs."

    }

    }

    ' in C:AppServwwwgooglevendorgoogleapiclientsrcGoogleHttpREST.php:118

    Stack trace:

    #0 C:AppServwwwgooglevendorgoogleapiclientsrcGoogleHttpREST.php(94): Google_Http_REST::decodeHttpResponse(Object(GuzzleHttpPsr7Response), Object(GuzzleHttpPsr7Request), NULL)

    #1 [internal function]: Google_Http_REST::doExecute(Object(GuzzleHttpClient), Object(GuzzleHttpPsr7Request), NULL)

    #2 C:AppServwwwgooglevendorgoogleapiclientsrcGoogleTaskRunner.php(181): call_user_func_array(Array, Array)

    #3 C:AppServwwwgooglevendorgoogleapiclientsrcGoogleHttpREST.php(58): Google_Task_Runner->run()

    #4 C:AppServwwwgooglevendorgoogleapiclientsrcGoogleClient.php(779): Google_Http_REST::execute(Object(GuzzleHttp in C:AppServwwwgooglevendorgoogleapiclientsrcGoogleHttpREST.php on

    Nishant Srivastav

    (August 6, 2019 - 2:04 am)

    How can we upload files in team drive?

    Jamshaid Kamran

    (August 6, 2019 - 2:04 am)

    So, I am supposed to upload videos files greater than several hundred MBs, So, to upload them I am first calling my server side code of C# asp.net and then handing over the file to google drive. Isn't any direct way of uploading files? javascript for asp.net servers? No?

    prakhar patidar

    (August 6, 2019 - 2:04 am)

    How to download already existing video files in drive? any initial thought?

    mogum loyi mogum Loyi

    (August 6, 2019 - 2:04 am)

    Whatever it May be it's a better lesson for everyone's to understand the living stength of human beings and a life of others need.

    mogum loyi mogum Loyi

    (August 6, 2019 - 2:04 am)

    Whatever it May be it's a better lesson for everyone's to understand the living stength of human beings and a life of others need.

    Young Nam

    (August 6, 2019 - 2:04 am)

    WHY DIS CODE NOT ON DOCUMENTATION!?!?!?!?!?!!?!?!?!!?

    Newbionic

    (August 6, 2019 - 2:04 am)

    I was waiting for him to say python

    Sharath Chandra

    (August 6, 2019 - 2:04 am)

    Is there a video to achieve same using Javascript?

    coderx3

    (August 6, 2019 - 2:04 am)

    this api is bat shit insane .

    Ja Ke

    (August 6, 2019 - 2:04 am)

    see at 3:16.

    Marina Doria

    (August 6, 2019 - 2:04 am)

    I run the same code and I had these errors: Can you help me please?

    Traceback (most recent call last):
    File "c:update_costsuploader.py", line 32, in <module>
    res = DRIVE.files().create(body=metadata, media_body=filename).execute()
    File "C:UsersllollAnaconda3libsite-packagesgoogleapiclientdiscovery.py", line 811, in method
    mimetype=media_mime_type)
    File "C:UsersllollAnaconda3libsite-packagesoauth2client_helpers.py", line 133, in positional_wrapper
    return wrapped(*args, **kwargs)
    File "C:UsersllollAnaconda3libsite-packagesgoogleapiclienthttp.py", line 550, in _init_
    fd = open(self._filename, 'rb')
    FileNotFoundError: [Errno 2] No such file or directory: 'hello.txt'

    Thoại Ngô

    (August 6, 2019 - 2:04 am)

    hi, how get link mp3 in google drive?r, thanks admin

    Raymond Khozanai Mlambo

    (August 6, 2019 - 2:04 am)

    I cant seem to get this right. It keeps throwing errors for me. Here is the error message
    CODE:
    from _future_ import print_function
    import os

    from apiclient import discovery
    from apiclient.discovery import build
    from httplib2 import Http
    from oauth2client import file, client, tools

    try:
    import argparse
    flags = argparse.ArgumentParser(parents=[tools.argparser]).parse_args()
    except ImportError:
    flags = None

    SCOPES = 'https://www.googleapis.com/auth/drive.file&#39;
    store = file.Storage('storage.json')
    creds = store.get()
    if not creds or creds.invalid:
    flow = client.flow_from_clientsecrets('client_secret.json', scope=SCOPES)
    creds = tools.run_flow(flow, store, flags)
    if flags else tools.run(flow, store)

    DRIVE = build('drive', 'v3', http=creds.authorize(Http()))

    FILES = (
    ('hello.txt', None),
    ('hello.txt', 'application/vnd.google-apps.document')
    )

    for filename, mimeType in FILES:
    metadata = {'name': filename}
    if mimeType:
    metadata['mimeType'] = mimeType

    res = DRIVE.files().create(body=metadata, media_body=filename).execute()
    if res:
    print('Uploaded "%s" (%s) ' % (filename, res['mimeType']))

    if res:
    MIMETYPE = 'application/pdf'
    data = DRIVE.files().export(fileId=res['id'], mimeType=MIMETYPE).execute()
    res, data = DRIVE._http.request(res['exportLinks'][MIMETYPE])
    if data:
    fn = '%s.pdf' % os.path.splitext(filename)[0]
    with open(fn, 'wb') as fh:
    fh.write(data)
    print('Downloaded "%s" (%s)' % (fn, MIMETYPE))

    ERROR:

    /Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6 /Users/raymondm/PycharmProjects/HelloWorld/Demos/v3_download_files.py
    Traceback (most recent call last):
    File "/Users/raymondm/PycharmProjects/HelloWorld/Demos/v3_download_files.py", line 35, in <module>
    res = DRIVE.files().create(body=metadata, media_body=filename).execute()
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/googleapiclient/discovery.py", line 815, in method
    mimetype=media_mime_type)
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/oauth2client/_helpers.py", line 133, in positional_wrapper
    return wrapped(*args, **kwargs)
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/googleapiclient/http.py", line 548, in _init_
    fd = open(self._filename, 'rb')
    FileNotFoundError: [Errno 2] No such file or directory: 'hello.txt'

    Geir Skårhaug

    (August 6, 2019 - 2:04 am)

    This was really expiring! Thanks a bunch!

    ABCDE

    (August 6, 2019 - 2:04 am)

    Google Drive API is hard to integrate in iOS.
    https://github.com/google/google-api-objectivec-client-for-rest/issues
    lots of issue not solve. Developers need to take a lot of time to solve these issues.

    tiska hardiana

    (August 6, 2019 - 2:04 am)

    Hello Mr. Wesley Chun
    My name is Tiska, i'm a college student. Recently I'm learning Google Drive API and I'm interested to learn more, because i want to develop the google drive apps for research in my college. would you mind to answering some question about drive API?
    and may i know your personal email account?
    thank you ^.^

Leave a Reply

Your email address will not be published. Required fields are marked *