App Logo
drive.google.com

Upload a file to Google Drive

Upload a file into a Google Drive folder, or into My Drive when no folder is given. Pass the bytes inline as base64 for small files, or point fileUrl at the file served over http://127.0.0.1:<port>/ on the machine running the browser for larger ones. Before reporting success it waits for a row in the destination that was absent beforehand AND carries this call's own filename, so it cannot credit itself with a file another upload created; it returns that file's Drive id. A filename already present in the destination is refused up front, because a dropped file does NOT replace or get declined — Drive happily stores a second, separate file under the same name. For the same reason a lost upload is reported as a failure rather than retried: a re-drop would duplicate an upload that merely landed slowly.

Input

filename required

Name to store the file under in Drive, including its extension. Must not already exist in the destination folder.

mime optional

Content type to store. Defaults to application/octet-stream, or whatever the server reports for a fileUrl.

fileUrl optional

URL the browser's own machine can fetch the file from, e.g. http://127.0.0.1:8765/clip.mp4 (python3 -m http.server 8765 in the file's directory). Mutually exclusive with fileBase64.

folderId optional

Destination folder id, i.e. the <id> in drive.google.com/drive/folders/<id>. Omit to upload into the root of My Drive.

fileBase64 optional

The file's bytes, base64-encoded. Suits files up to roughly 96KB; use fileUrl above that. Mutually exclusive with fileUrl.

Output

fileId required

Drive file id of the newly created file.

folderId required

Destination folder, or "root" for My Drive.

uploaded required

The filename as Drive stored it.

verified required

Always named_row_appeared: a row absent from the folder before the upload AND bearing this call's own filename. The script fails rather than reporting an unconfirmed upload, and will not credit itself with a file another run created.

bytes optional

Size of the payload uploaded.

Start building not clicking