0

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

Community
  • 1
  • 1
noisyBlue
  • 1
  • 2

1 Answers1

0

As stated in the answer on the similar post you included, it is being advised to use uploadType=resumable since the file size being uploaded is high. It pretty much is the solution to your issue. As per the Upload Files document:

Simple upload

For quick transfer of smaller files, for example, 5 MB or less.

Resumable upload

For reliable transfer, especially important with larger files.

Nimantha
  • 6,405
  • 6
  • 28
  • 69
AL.
  • 36,815
  • 10
  • 142
  • 281
  • I've tried using `uploadType=resumable` before. However, the log report this error `Exception: Unsupported content with type: multipart/related` I've tried not to set mimeType parameter, but still got this error – noisyBlue Apr 17 '16 at 07:23
  • I think that's now a different concern from your original post. I suggest posting a new one, along with the details, things you did, resources you checked, and some code snippets that you think might be useful for the community to be able to help you. :) – AL. Apr 18 '16 at 00:26