Skip to content

Commit 113187e

Browse files
committed
docs: add docs for creating a GoogleDriveFile by ID
1 parent 15f3e6d commit 113187e

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

docs/file.rst

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ Table of Contents
4444
oauth
4545
filemanagement
4646
filelist
47+
file
4748
fsspec
4849
pydrive2
4950
genindex

0 commit comments

Comments
 (0)