🟦 Update/Replace Existing File on Google Drive, Keeping the Same File ID

This demo guide shows you how to update an existing file on google drive through App Inventor. This method retains the original file ID, therefore this can be useful where you may have links to a specific file on Google Drive.

7 Likes

It works for me!

At first the update did not work for me, only the upload of the first file worked.
When updating I got the error:
"Drive" is not defined "

I went to Resources - Advanced Google services and checked
Drive API v2, now updates work for me.

A small change, maybe it is not necessary to upload the "mimetype" since we can obtain it directly in the Script:

Drive.Files.update ({title: filename, mimeType: file.getMimeType ()}, fileID, blob);

Thanks Juan, I kept meaning to add that to the guide, but kept forgetting!! Will add it now :wink: [edit - done]

Regarding your second point, I haven't tested it but, it is probably possible to upload a different mimetype to the same filename, e.g. a jpg file to a file named .myImage.png. You can leave off the file extension to avoid confusion, just calling it myImage, and upload any mimetype you like to the file, retaining the fileID.

The Web App Script URL - where exactly does one publish the script?

and

Hello @Juan_Antonio I can't see the option of the legacy editor like this:

I only see this options:

How can I enable the option of legacy editor?.

Now I also can't get the "Usar el editor antiguo", probably Google has removed that option.

1 Like

Ok, so there is another way in order to update a file from App Inventor to google Drive?

Are you unable to use the "new editor" ? The script will be the same, and work in the same way.....

Yes, I can use the new editor, but I don't found this option: Resources > Advanced Google Services, then setting "Drive API" to "On".

Here I have adapted @TIMAI2's Script to various examples from this Community with Drive and Sheets.
I don't remember if it updates the image or not.
http://kio4.com/appinventor/763B_SubirGoogleDrive.htm

Now under Services....

1 Like

Thanks a lot @TIMAI2 , found it.