Skip to content
Advertisement

Python : upload my own files into my drive using Pydrive library

I want to upload my file into my drive. However in Pydrive Documentation I found only upload() function that uploads a file created by drive.CreateFile() function and update it, and not the file in my hard drive (my own file).

JavaScript

I’ve tried the ansewers of my question here in stackoverflow, but an error accured . here is my code :

JavaScript

The file “big.txt” is in the same folder of my code file. When I run it, I got this traceback:

JavaScript

Advertisement

Answer

You have to set the content with SetContentFile() instead of SetContentString():

JavaScript

As the documentation states, if you haven’t set the title and mimeType they will be set automatically from the name and type of the file your give. Therefore if you want to upload the file with the same name it already has on your computer you can do:

JavaScript

Regarding your second point, as far as I’m aware GDrive can not convert a file to a different format.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement