I've newer from Google Script and trying to establish a script supporting anonymous upload to Drive (https://ctrlq.org/code/19747-google-forms-upload-files).
What I've done so far is able to run the script and found out folder.createFile(blob)
function cannot upload with filesize more than 10Mb. I then found out using Advanced Drive Service(Drive API) may able to provide the fix, so I change using Advanced Service(Drive
rather than DriveApp
) (https://developers.google.com/drive/v2/reference/files/insert#http-request). However, It then response the error Exception: Empty response
.
Here is my code.
function uploadFiles(form) {
try {
var blob = form.file;
var contentType = blob.type;
var folderName = "Upload Folder";
var folder, folders = DriveApp.getFoldersByName(folderName);
if (folders.hasNext()) {
folder = folders.next();
} else {
folder = DriveApp.createFolder(folderName);
}
var file = {
title: blob.name,
mimeType: contentType,
parents:[{id:folder.getId()}]
};
var options = {
uploadType: "multipart"
};
file = Drive.Files.insert(file, blob, options);
return "File uploaded successfully " + file.fileSize;
} catch (error) {
return error.toString();
}
}
It can upload <10Mb file by using above code(on both uplaodType: media
and multipart
). However, >10Mb still failed, would it be needed to use resumable
?
Remark: I've noticed there was a question similar to the issue I've encountering(Advanced Drive Service returning Empty Response Error when inserting file), but seems there is no conclusion at that point, so I wish somebody can help fixing this issue