How can i upload zip file from mobile to google drive?

How can I upload zip file from mobile to google drive, can someone help me?

See

Dora, thanks for your answer. I have explored the help you gave me, I see that it is to upload images to google drive, but how do I read zipped or compressed files that are on the mobile device to upload them to google drive

Just use the same method in the main howto:

  • select the zip file to be uploaded
  • encode the file to base64
  • set the mimetype for the file
  • send the filename, mimetype, and base64String to the google apps script using the web component
  • see your zip file on google drive

Thank you very much for your help, could you please help me, what would be the procedure to select a zip file that is stored on the mobile?, since finally this is the one I want to upload to the google drive.

You can use Taifun's File extension to list files in a directory, select one that way?

Your zip file will need to be in a location that is accessible from the app.

And which one would that be (especially on Android 11+)?
Only the ASD could be considered for this. However, this would mean that the zip file would have to be manually copied / moved there by the user. In this respect, only SAF remains as a solution.

If the zip file isn't created by the app itself, you won't be able to access or list it without SAF unless that file is in the ASD. At least not on devices running Android 11+.

It works for media files, but not for non-media files (.txt, .pdf, .zip etc).
Where does the zip file come from?

The OP has not given any indication on where the zip file is. It could have been created in the ASD by Taifun's zip extension, we just do not know....

The ZIP file has been created with the application and in the blocks I have placed the path where the zip file is located on the mobile according to the image:
/Android/data/appinventor.ai_user.aplication/files.zip)

According to the help, these blocks also allow me to upload ZIP files to the drive.

If the ZIP file was created by the app, it doesn't matter whether the file is in the ASD or in one of the shared folders. It can be accessed on all Android versions.

The yellow marked blocks make no sense:

Show also the blocks where the zip file was created.

The zip has been created in the same place where you want to share to google drive.

image

It doesn't have to be over complicated......

Herewith a full example.

I have created a folder on Google Drive called ZipFiles, and got it's folder ID.
This is now an additional parameter in my google apps script:

function doPost(e) {

    var data = Utilities.base64Decode(e.parameters.data);
    var blob = Utilities.newBlob(data, e.parameters.mimetype, e.parameters.filename);
    var fileID = DriveApp.getFolderById(e.parameters.folderId).createFile(blob).getId();
    return ContentService.createTextOutput("Zip file ID: " + fileID);

    }

The script will return a string containing the ID of the zip file just uploaded.

Here are the blocks:

  • I use a File component and a procedure to identify the ASD pathway
  • A zip file is created in the ASD of the Pictures folder
  • On creation, I get the path to the file, and extract the filename
  • To upload the file to Google Drive:
    • I first convert the zip file to a base64 encoded string
    • Then upload the folderId, filename, mimetype and base64String to the web app
  • The web app converts the base64 back to a binary file and saves it to the designated folder
  • The web app returns the ID of the zip file

Screen

image

Google Drive

image

1 Like

The path to the ASD should not be hard-coded.
The // in front of the file name doesn't make sense either.

And as you can see in the blocks from @TIMAI2 the TaifunZip extension also works with the absolute or full path.

Excellent thank you very much for your help, I have been able to upload my zip file to google drive, but I can only upload from the companion or when I am emulating, however when I have it compiled as Apk it does not compress and it does not upload to google drive either, thanks for your help.

Did you ensure that your compiled app had a /Pictures folder in the ASD that contained files ?

I had an error when compiling but it has been resolved, Thank you very much everyone for your time. They are all very good.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.