App Inventor picture safe to google formula/spreadsheets

Hello,
my name ist Ben. I have a problem to safe pictures from camera function of appinventor to google spreadsheets.
How can I safe the pictures of my app to a google sheet / formula?

I would be really happy if you can help me :slight_smile:

greetings Ben

HOWTO: Upload Image to Google Drive using base64 using Camera Image

Also

1 Like

Hello Tim,

I read a lot of your solutions. Great work!
I would like to build an app like yours: https://groups.google.com/d/msg/mitappinventortest/liWppNXqHXM/5Ht506yRBwAJ

It donĀ“t works with my settingsā€¦

  1. I downloaded your project: ā€œupload_CameraImage_Locatiā€

  2. I created a new folder and a new spreadsheet (and did it public)

  3. I added in the spreadsheet a script with following code:

    function doGet(e) {
    return message(ā€œError: Please Try Againā€);
    }
    function doPost(e) {
    if (!e.parameters.filename || !e.parameters.file || !e.parameters.imageformat) {
    return message(ā€œError: Please Try Againā€);
    } else {
    var imgf = e.parameters.imageformat[0].toUpperCase();
    var mime =
    (imgf == ā€˜BMPā€™) ? MimeType.BMP
    : (imgf == ā€˜GIFā€™) ? MimeType.GIF
    : (imgf == ā€˜JPEGā€™) ? MimeType.JPEG
    : (imgf == ā€˜JPGā€™) ? MimeType.JPEG
    : (imgf == ā€˜PNGā€™) ? MimeType.PNG
    : (imgf == ā€˜SVGā€™) ? MimeType.SVG
    : false;
    if (mime) {
    var data = Utilities.base64Decode(e.parameters.file, Utilities.Charset.UTF_8);
    var blob = Utilities.newBlob(data, mime, e.parameters.filename);
    var imageID = DriveApp.getFolderById(ā€˜1KeLyPsYujVN3DSLJ0nr2XdpQi93EvAkXā€™).createFile(blob).getId();
    // ID of my folder
    var lat = e.parameters.lat[0];
    var lon = e.parameters.lon[0];
    var add = e.parameters.address[0];
    var name = e.parameters.filename[0];
    var viewurl = ā€œhttps://drive.google.com/uc?export=view&id=ā€ + imageID;
    var ss = SpreadsheetApp.getActive();
    var sh = ss.getSheets()[0];
    sh.appendRow([lat,lon,add,imageID,name,viewurl]);
    return message(ā€œSuccess: Image Uploaded and Data Savedā€);
    } else {
    return message(ā€œError: Please Try Againā€);
    }
    }
    }
    function message(msg) {
    return ContentService.createTextOutput(msg);
    }

  4. Change the script text in project .aia

  5. run the project.
    Camera works, but after upload ā€œError: Please Try Againā€

Tim can you helb me please?What is wrong?..
Thank you :slight_smile:

You donā€™t show your PostText blocks (SendeText) ?

Hello Tim,

here the full block:

I just changed the web1.Url

Check that all of the variables (hole), especially the first three are correct (use Do It in Companion)

Also confirm that you have republished the script after changes, and that it is published as your google account and that anyone, even anonymous can access it.

Hello Tim,
thank you so much for support!

The solutions is the correct republishment:

I added a text box and it works that I can send the picture and the text to my google spreadsheet.
But one question more, how can I send just the text? The case could be that I dont need to take a picture.

greetings Ben

Then you would need a different script:

You are doing the same thing, but without the image

Hi Tim,

thank you for fast support.
I would like to work in one app/screen. So when I have a text and a picture then save both in spreadsheet (this works), when I have no picture then just save the text.
Can you help me with this case?

Thanks a lot!

I just did. Use a a different script. You can target the same sheet on the spreadsheet.

Hello Tim,

I would like to use the same button. I dont think that would be work with 2 scripts.

You can, just use some logic:

Button press
If no image then run script 1
else
run script 2 (for image)

Hi TIm,

I did it. Thank you!
I am sure I dont have the nicest way but it works :slight_smile:

Can you tell me where the pictures are located? I dont find the picture manually in my google drive.
I want to know where the space is used.

EDIT: Oh ok, i found it in the search. Can you tell me why the pictures are hidden?

greetings Ben

The image files are uploaded to the folder indicated in this line in the script/scripts:

DriveApp.getFolderById(ā€˜1KeLyPsYujVN3DSLJ0nr2XdpQi93EvAkX'.createFile(blob).getId();

I hadnā€™t noticed, but because you have been using the folder I presented in my demo, they are going to a shared folder on my google account. !!

You need to use your own folder, set the sharing accordingly, and change your script/scripts, then republish etc.

You can find the folder ID in the url address bar when you open the folder in Google Drive

hello Tim,

I think I use my folder and my spreadsheet.
DriveApp.getFolderById(ā€˜1KeLyPsYujVN3DSLJ0nr2XdpQi93EvAkXā€™.createFile(blob).getId();
this is the Folder ID of my account

Well that is where your images are then, someone used my folder this morning :wink:

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