|
| 1 | +File referencing made easy |
| 2 | +============================= |
| 3 | + |
| 4 | +*PyDrive* can create a single `GoogleDriveFile`_ if you already know |
| 5 | +the file's ID. |
| 6 | + |
| 7 | +Specify a file by ID |
| 8 | +-------------------- |
| 9 | + |
| 10 | +Create a `GoogleDriveFile`_ instance with a ``dict`` specifying the |
| 11 | +Google Drive file ID. Then call the various ``GetContent*()`` methods |
| 12 | +(i.e., `GetContentString()`_, `GetContentFile()`_, and |
| 13 | +`GetContentIOBuffer()`_) to download contents of that file. |
| 14 | + |
| 15 | +.. code-block:: python |
| 16 | +
|
| 17 | + import mimetypes |
| 18 | + from pydrive2.files import GoogleDriveFile |
| 19 | +
|
| 20 | + # Download a file as a PPTX (e.g., a Google Slides file, or even |
| 21 | + # an actual PPTX file) |
| 22 | + def download_pptx(id, output_file='my-slides.pptx'): |
| 23 | + mtype = mimetypes.guess_type(output_file)[0] |
| 24 | + gfile = GoogleDriveFile(gauth, {'id': id}) |
| 25 | + gfile.GetContentFile(filename=output_file, mimetype=mtype) |
| 26 | +
|
| 27 | + # Download a text file as a string |
| 28 | + def download_text_file(id): |
| 29 | + mtype = 'text/plain' |
| 30 | + gfile = GoogleDriveFile(gauth, {'id': id}) |
| 31 | + return gfile.GetContentString(mimetype=mtype) |
| 32 | +
|
| 33 | +.. _`GoogleDriveFile`: /PyDrive2/pydrive2/#pydrive2.files.GoogleDriveFile |
| 34 | +.. _`GetContentFile()`: /PyDrive2/pydrive2/#pydrive2.files.GetContentFile |
| 35 | +.. _`GetContentString()`: /PyDrive2/pydrive2/#pydrive2.files.GetContentString |
| 36 | +.. _`GetContentIOBuffer()`: /PyDrive2/pydrive2/#pydrive2.files.GetContentIOBuffer |
0 commit comments