Advanced Drive Service returns a blank response error when inserting a file

This is a continuation of Using the extended disk service to download files .

My Webapp consists of a form for uploading data files, which are then saved to Google Drive. (The full code is in the snippet below.) I had a problem with the following line of code:

var file = Drive.Files.insert(resource, mediaData); // create file using Drive API 

  try { //Get root folder and pull all existing folders, plus setup variables pulled from form var dropbox = form.Country; var timeStamp = new Date(); //Set file name slightly differently for Weekly Member Report (do not want to overright based on name just keep each extract so add timestamp to name) if (form.reportType == "Member Weekly"){ var filename = form.reportType + timeStamp + ".xls"; } else { var filename = form.reportType+".xls"; } var rootfolder = DriveApp.getFolderById("0Byvtwn42HsoxfnVoSjB2NWprYnRiQ2VWUDZEendNOWwwM1FOZk1EVnJOU3BxQXhwU0pDSE0"); //Note root folder is Live Uploads Folder in Flatworld App folder structure var folder, folders = rootfolder.getFoldersByName(dropbox); //Check if folder exists and if not create if (folders.hasNext()) { folder = folders.next(); } else { folder = rootfolder.createFolder(dropbox); } var FolderURL = folder.getUrl(); // Retain URL of folder for final end message to user //Check if file already exists and delete if it does var file, files = folder.getFilesByName(filename); while( files.hasNext()){ file = files.next(); file.setTrashed(true); } //New Code from Stackover Flow: //Upload file and set various properties var mediaData = form.myFile; var resource = { title: filename, mimetype: 'application/vnd.ms-excel', description: "Uploaded via BNI Upload Form by " + form.myName + " on: " + timeStamp }; var file = Drive.Files.insert(resource, mediaData); // create file using Drive API var fileId = file.id; var DriveAppFile = DriveApp.getFileById(fileId); // retrieve file in DriveApp scope. var FileURL = DriveAppFile.getUrl(); //Retain URL of file for final end message to user DriveApp.removeFile(DriveAppFile); // remove new file from Users root My Drive folder.addFile(DriveAppFile); // puts file in selected folder //End of New code from Stackover Flow //Success message displayed to user return "Thanks! File uploaded successfully to: <br><br><b>Folder Location:</b> " + FolderURL + "<br>" + "<b>File:</b> " + FileURL + ". <br><br>For any queries please email user@example.com copying the URLs displayed here in your email. You can close this browser window now or use the link below to upload another file.<br><br>"; } catch (error) { //Catch error return it to user and email with error details 

It gives the “Empty Response” error message in the line of code above when we try to download a large file (15 MB). Do you have any suggestions. This is well within the insertion limit of 5120 GB files, and the code works fine on small files.

Now I tried to add a function to the loop to try to load a couple of times, still throwing the same error:

  //setup function that will return null if file is not uploaded correctly function createDriveFile(resource_f, mediaData_f){ try{ var file = Drive.Files.insert(resource_f, mediaData_f); // create file using Drive API return file; } catch (e) {return null;} } //try upload and loop if null var maxTries = 3; var tries = 0; do { tries = tries + 1; if (tries > 0) { var file = createDriveFile(resource, mediaData); Logger.log("I'm trying to upload, try number: " + tries); } } while ((file == null) && (tries < maxTries)); if (file == null) { var file = Drive.Files.insert(resource, mediaData); // try one laste time to create file using Drive API - outside loop function so if error is thrown script stops } 

The error occurs only in a larger file, even if we reduce the size of the same file, which solves the error, so we need to configure the download process to account for the larger file. Is there an equivalent to Google Apps Script that allows you to renew the API download request

+4
google-drive-sdk google-apps-script google-drive-realtime-api
source share
1 answer

The size of your file is the determining factor here. The documentation link shows that the simple download method used here is only good for 5 MB.

https://developers.google.com/drive/web/manage-uploads

Your comments seem to confirm that this is happening to you.

As you hinted, use the renewable boot method. Use the uploadType: resumable parameter flag - the API documents in the insert method describe how.

+1
source share

All Articles