Backup in users google drive

Hello TIMAI2,

you wrote that the folderID is also given in the stringified JSON array. How can I read out the folderID for my folder name "Testapp"?
Can you please show me a block for that too?

I definitely need this folderID for the TargetID in "UploadFileToFolder", correct?

Thanks Frank

You need index 2 from the item in global RootFolders (when you do a for each item)

Thank you TIMAI2

One more question, sorry.

What is the targetID in "UploadFileTo Folder"? Is this the folderID of the "Testapp" folder?
Or how does the tagetID have to be assigned?

Frank

The targetID is the Id of the folder you wish to upload the file to. You use the folderID for this. Therefore if you want to upload a file to the folder "Testapp", you must get this folders ID and set it as the targetID. :slight_smile:

Hello TIMAI2,

it still doesn't work.
Here the block:

There is no error message, the file is not written to the folder in Google Drive.
I checked the folderID, it gives the correct name for the folder.

What have I done wrong?

Frank

Possible omission by me, there is no db file type in the MimetypesList and I should have put application/octet-stream in the notFound socket like so:

Also edit global filename to just filename

Also, you can debug all of your variables to ensure that they are correct - e.g. do you actually have a base64string, is the filename returning true, is the target folderID in place

Hello TIMAI2,

with a small file (*.db) it works now. The file ends up in the right folder on GD.

Then I tried a zip file with a size of about 10MB. This file is not written to GD.

My block for this is:

Frank

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