Now in this block of code we will be uploading files to google drive with pydrive library. So copy paste this code just below the authentication code.
Save my name, email, and website in this browser for the next time I comment. Skip to content. SetContentFile os. Due to a known bug in pydrive if we. Recommended Articles. Article Contributed By :. Easy Normal Medium Hard Expert. Writing code in comment? Here is the code snippet :. I had a similar problem with G-sheets, the problem here is that there might be multiple formats to download the file in and you're not specifying which one you want. To do this you need to add the mimetype parameter to the GetContentFile Method.
Like so:. Note that there are multiple mimetypes for zip files and that the mimetype and extension need to agree. So you need to know which one to use, or just try out different ones if you don't. Here's a handy list:.
Furthermore, if you actually access the metadata of the file you can have a peek at all the types of formats you can export it in under 'exportLinks'. There will be a dict with mimetypes and the associated links. It basically looks for token. Going to the main function, let's define a function that lists files in our drive:. So we used service. Since results are now a list of dictionaries, it isn't that readable, we pass items to this function in order to print them in human-readable format:.
We converted that list of dictionaries items variable into a list of tuples rows variable, and then pass them to tabulate module we installed earlier to print them in a nice format, let's call main function:. The above function should be defined before running the main method, otherwise, it'll raise an error. For convenience, check the full code.
Remember after you run the script, you'll be prompted in your default browser to select your Google account and permit your application for the scopes you specified earlier, don't worry, this will only happen the first time you run it, and then token.
Note: Sometimes you'll encounter a "This application is not validated" warning since Google didn't verify your app after you choose your Google account, It's okay to go "Advanced" section and permit the application to your account.
Different scope means different privileges, you need to delete token. Connect to the API service. Initialise a downloader object to download the file. Download the data in chunks.
Write the received data to the file. Return True if file Downloaded successfully. Return False if something went wrong. Extract the file name out of the file path. Find the MimeType of the file. Create a new file in the Drive storage.
Raise UploadError if file is not uploaded. Previous How to access the last element in a Pandas series? Recommended Articles. Article Contributed By :.
0コメント