Upload from camera to google drive (camera)

108 views
Skip to first unread message

Ezra Epriputra

unread,
May 13, 2019, 8:37:02 AM5/13/19
to MIT App Inventor Forum
Hai TEAM AI2...
Thanks berfore for read my questions...
i see some tutorial about upload image to google drive...i made little bit modification with add camera component in it...
but i found error when i take the pic with camera...
i know its wrong image...can you help me with this?teach me how to fix it...

Thanks before for your answer

blocks(1).png

errorfoto.png


Message has been deleted

BodyMindPower

unread,
May 13, 2019, 12:23:54 PM5/13/19
to MIT App Inventor Forum

Ezra Epriputra

unread,
May 13, 2019, 11:51:52 PM5/13/19
to MIT App Inventor Forum

Ezra Epriputra

10:22 (27 minutes ago)
to MIT
thanks...i try with extension and works...
do you have tutorial how to store image from google drive to APP inventor?
i see several tutorial...and its should make URL and get the image ID...

TimAI2

unread,
May 14, 2019, 12:41:41 PM5/14/19
to MIT App Inventor Forum

Ezra Epriputra

unread,
May 15, 2019, 12:56:58 AM5/15/19
to mitappinv...@googlegroups.com


Many Thanks for all that Tutorial...its help me alot...
I've triy this tutorial...
 and copy paste and modified the script...i want not only the get the ID image but the File Name too...
i made modification like this...sory i really newbie at Google Apps Script

function doGet(e) {
 
return message("Error: no parameters in doGet");
   
}

function doPost(e) {
 
if (!e.parameters.filename || !e.parameters.file || !e.parameters.imageformat) {
   
return message("Error: Bad parameters in doPost");
 
} 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);
     
     
//get the image file ID like this:
     
var imageID = DriveApp.getFolderById('myfolderIDlink').createFile(blob).getId();
     
var imageName = DriveApp.getFolderById('myfolderIDlink').createFile(blob).getName();
     
     
//append the ID to your spreadsheet like this:
     
var ss = SpreadsheetApp.openById('SSIDlink');
     
var sh = ss.getSheets()[0];
      sh
.appendRow([imageID, imageName]);
     
     
return message("Success");
   
} else {
     
return message("Error: Bad image format");
   
}
 
}
}

function message(msg) {
 
return ContentService.createTextOutput(JSON.stringify({Result: msg })).setMimeType(ContentService.MimeType.JSON);
}

and the result is, i get the file name too...but in my google drive...everytime i upload image,its always make 2 same file image...
is there anything wrong with the script?
i not change the block...just renew the link everytime i made some change in script...

TimAI2

unread,
May 15, 2019, 5:33:25 AM5/15/19
to MIT App Inventor Forum
Try changing

var imageName = DriveApp.getFolderById('myfolderIDlink').createFile(blob).getName();

to

var imageName = DriveApp.getFileById('imageID').getName();



Ezra Epriputra

unread,
May 15, 2019, 6:16:22 AM5/15/19
to MIT App Inventor Forum
Thanks...its work...

I try to find the tutorial about compressing image size with app inventor...but couldnt get any...

So after get image from camera, i need to compressing before send it to google drive...

Help me if you have link tutorial about compressing image size...and thanks before for your help always teach me...

TimAI2

unread,
May 15, 2019, 6:19:37 AM5/15/19
to mitappinv...@googlegroups.com
Try Taifun's Image extension, it has a resize feature

or, if you do not want to use an extension, you could try loading the image into a canvas then doing a canvas.saveas, you have no control over the output, but it may reduce things, depending on the size of the canvas ?
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted

Ezra Epriputra

unread,
May 15, 2019, 11:39:54 AM5/15/19
to mitappinv...@googlegroups.com
I try to combine resize process and uploading image to Google Drive...
the resize process is succes...but i dont know how to upload the resize image to google drive..
its always the not resizing image uploaded into google drive...
please teach me the right block..here is my aia
uploadImage2GoogleDrive1resize.aia

TimAI2

unread,
May 15, 2019, 1:16:06 PM5/15/19
to MIT App Inventor Forum
Are you saving the resized file ? It could be that the resized image/data is only in memory and you will need to save it first before uploading ? Or perhaps save as a different image...?

Ezra Epriputra

unread,
May 15, 2019, 11:00:12 PM5/15/19
to MIT App Inventor Forum
okay thanks...i think i prefer use Canvas because it's have low size with sharp image...

is all canvas image extension is .png?
Reply all
Reply to author
Forward
0 new messages