News
-
At October 11, 2019, I published a Javascript library to to run the resumable upload for Google Drive. When this is used, the large file can be uploaded. You can also use this js library.
Overview
This is a sample script for uploading files with large size (> 50 MB) at Web Apps using Google Apps Script (GAS). The resumable upload method is used for uploading files. This script can be also applied to the script using gapi of javascript.
Demo
This is a demonstration of this script. As a demonstration, it uploads a file with the size of 100 MB to my Google Drive. When the file was selected, it is uploaded by the resumable upload. It is found that the file can be completely uploaded.
Description
Have you ever thought that you want to upload files with large size from local PC at Web Apps using GAS? Recently, I have thought it. So I investigated about this situation. At first, it was found that there are some limitations for uploading files to Google Drive from local PC.
- When “uploadType” is used as “media” and “multipart”, the limitation of size is less than 5 MB (5,242,880 bytes).
- This is the specification of Drive API.
- When “google.script.run.function(file)” is used, the limitation of size if less than 50 MB (52,428,800 bytes).
- This is the specification of “DriveApp.createFile(blob)”.
- “blob” can be used for the size more than 50 MB. But a file cannot be created using “DriveApp.createFile(blob)”. Furthermore, “blob” with the size more than 50 MB cannot be converted to the byte array.
- This is due to my experiments.
When users want to upload files with the size more than 50 MB to Google Drive, the Resumable Upload is required to be used. As the next step, although I have looked for the sample script, Unfortunately, I couldn’t find it. So I created this. The flow of this sample script is as follows.
- Retrieve a file.
- Retrieve an access token from GAS.
- In this sample script, GAS is mainly used for retrieving the access token.
- Retrieve the endpoint for the resumable upload using the access token.
- Upload chunks for the resumable upload to the endpoint.
If this was useful for you, I’m glad.
You can check this at https://github.com/tanaikech/Resumable_Upload_For_WebApps.