Backup in users google drive

This, below, is commented in the google apps script:

//uploadFile(e.parameter.name,e.parameter.data,e.parameter.mime)
//Note: the webviewer can only handle file sizes of @ 1.2mb 
//(when in base64String), for larger files, 
// temporarily change folder permissions to anyone_with_link, 
//step outside the framework and use the web component
//to upload, then back into the framework to reset permissions. 
//For root folder you will need to upload to another folder, then move to root.

nothing I can do about this, the webviewer can only handle a url of a certain size.

Hello TIMAI2,

thanks for the information.
It's a shame that this restriction exists to WebViewer.

Do you have an idea or a link how I can copy larger files?

(//for larger files, temporarily change folder permissions to anyone_with_link,
//step outside the framework and use the web component
//to upload, then back into the framework to reset permissions.)

Frank

Should be something like this (not tested - might need to specifically share the folder with the google account owner of the script)

open up the folder to anyone
upload larger file to folder
lock down the folder

You will need to introduce a file size test in order to activate the larger file option.

Hello TIMAI2,

i tried to apply your block.
Unfortunately it doesn't work yet.

In the web1.posttext
join has the following content:

Do It Result: "func=upFileToFolder&folderID=1pISU-y2sSOXmofrkMU3Dxxxxxxxxxxx&filename=Pictures.zip&mime=data:application/zip&data"

get global base64String is empty. Is that how it's supposed to be?

Frank

I assumed you would encode the file to a base64String....

And how would that be possible?

In the same way that you encoded it before, blocks are provided for this purpose

image

image

Thanks TIMAI2,

I have now solved it like this.

Unfortunately it does not work. No file is transferred.

I used GDConnector2 since GDConnector1 copies the small file. I hope it works like this.

The Runtime Error is: Attempt to invoke virtual method 'void android.webkit.WebView.loadUrl(java.lang.String)' on a null object reference

Frank

A bit more time now, working on it.

Also check your mimetype procedure, need to change global filename to local filename.

I think it will probably need a different web app script, security just too good :wink:

Hello TIMAI2,

First of all, thank you very much for your efforts.

An important part of my intention to secure the data of the app is achieved with the storage of the database file.

It would be good to save the pictures (Pictures.zip), but this is probably not possible with AI2 at the moment.

If you discover another possibility, please report it here in the thread.

Especially if there is a new web app script that will help me transfer large files to GD.

Frank

Try this, for larger files, it should work:

  1. Create a new standalone google apps script project
  2. Add this code:
function doPost(e) {
  // upload file to Root
  if ( e.parameter.func == "upFile" ) {
  return uploadFile(e.parameter.name,e.parameter.data,e.parameter.mime)
  }
  
  // upload file to Folder
  else if ( e.parameter.func == "upFileToFolder" ) {
  return uploadFileToFolder(e.parameter.name,e.parameter.data,e.parameter.mime,e.parameter.targetID)
  }
  
}


function uploadFileToFolder(name,data,mime,targetID) {
  var fileData = Utilities.base64Decode(data, Utilities.Charset.UTF_8);
  var blob = Utilities.newBlob(fileData,mime,name);
  var upFile = DriveApp.getFolderById(targetID).createFile(blob);
  var output = "upFileToFolder::" + upFile.getName() + "::" + upFile.getId();
  return ContentService.createTextOutput(output);
}

function uploadFile(name,data,mime) {
  var fileData = Utilities.base64Decode(data, Utilities.Charset.UTF_8);
  var blob = Utilities.newBlob(fileData,mime,name);
  var upFile = DriveApp.getRootFolder().createFile(blob);
  var output = "upFile::" + upFile.getName() + "::" + upFile.getId();
  return ContentService.createTextOutput(output);
}
  1. Publish as a web app

image

if using the new script editor, select Anyone

  1. Blocks
  • open up the sharing for the folder to save the file to:

  • encode the file to base64String (you can add additional if/else blocks to the encode event, using the setting of the action variable, so that you do not have to drag in another copy of the extension)
    image

  • POST the file with the required parameters to the script web app

  • handle the return, and reset the folder permissions

  1. Bear in mind that Google/Google Drive does not always behave in the way we may expect, it may not be happy with uploads of files over 25mb, or too many uploads in a particular time period.

######################
######################

Not sure what you mean by this, you should be able to upload a Pictures.zip file to a folder in the same way.

Sorry TIMAI2,

it not works.

The Runtime Error is: Attempt to invoke virtual method 'void android.webkit.WebView.loadUrl(java.lang.String)' on a null object reference

Here my blocks:

Frank

What is the output for base64String (you will need a variable or a label) and your mimetype?

output getMimeType: Do It Result: "application/octet-stream" ---

and base64String (screenshot from ShowMessageDialog)

The string is longer as you can see here.

Frank

Are you using a different google account to authenticate with the web app (to the one that created it) ?

Yes, one account for programming and one for testing.

The runtime error indicates a problem with your blocks, not sure where it is coming from, because you were getting this error before the last set of changes. It is possibly the second instance of GDConnector?

WebView is null. @TIMAI2

1 Like

I am currently working on removing the 2nd instance of GDConnector and testing everything.
I will report then.

Frank

1 Like