Hi community, I am new to ai2 app, I have this project for a product inventory application.
I was reviewing some threads, specifically, the mentioned ones and in METRIC RAT AI2 everything available, I tried to use the .aia Jean_Yves_Le_Magnifi and deff_brian creating my own Scripts in Apps Script and modifying the blocks with the links of the macros and the ID of the folders but I didn't get the joke.
I'm still using the "com.ghostfox.SimpleBase64.aix" extension to upload the image to drive as it was the first one I learned to use.
The thing is that my goal is to send an image to a drive folder and generate the share link of the same image in a spreadsheet, in the first instance and I was also looking at how to use the cell phone camera to photograph each product from the same app, as I was using an ImagePicker to upload the corresponding image and it is not very practical to be opening the native camera to photograph and then the inventory application to upload the image, there is a way to call my camera and use everything in the same app.
function doPost(e) {
var ss = SpreadsheetApp.openById('1O8zf1SB5c7zJPCFM37yttMVdpNmImDPBQRdzMrDLt-M');
var sh = ss.getSheetByName('TIMAI2_demo');
var tag1 = e.parameter.tag1;
var tag2 = e.parameter.tag2;
var name = e.parameter.name;
var mimetype = e.parameter.mimetype;
var data = e.parameter.data;
var filename = name + "_" + Utilities.formatDate(new Date(), "GMT+4", "dd-MM-yyyy-HH-mm");
var data = Utilities.base64Decode(data);
var blob = Utilities.newBlob(data, mimetype, filename);
var fileID = DriveApp.getFolderById('1KcFjtRmyYG8yb82L8BKI1g8dysOJ8lxA').createFile(blob).getId();
var file = DriveApp.getFileById(fileID);
file.setSharing(DriveApp.Access.ANYONE_WITH_LINK, DriveApp.Permission.VIEW);
var fileUrl = "https://drive.google.com/uc?export=view&id=" + fileID;
sh.appendRow([tag1,tag2,filename,fileUrl])
return ContentService.createTextOutput("Data uploaded");
}
It is with this code, isn't it? only that it is specified in the blog that: "(you will need to amend the workings of the Web1.GotText blocks accordingly)"
Done some work for you, created a simple inventory app that take a photo from within the app, then uploads to google drive and sets data to spreadsheet. I used my remix of the procam extension to handle the taking of a photo and converting to base64. All data is saved to google, no data is saved to the device.
function doPost(e) {
var ss = SpreadsheetApp.openById('<YOUR SPREADSHEET ID HERE>');
var sh = ss.getSheetByName('Sheet1');
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();
var rowData = [];
rowData.push(e.parameters.itemName[0]);
rowData.push(e.parameters.itemDescription[0]);
rowData.push(e.parameters.itemValue[0]);
rowData.push(e.parameters.filename[0]);
rowData.push(fileId);
rowData.push('https://drive.google.com/file/d/' + fileId);
sh.appendRow(rowData);
return ContentService.createTextOutput('Image: ' + e.parameters.filename + ' with ID: ' + fileId + ' successfully uploaded to Google Drive' );
}
Hi, you are just phenomenal, thank you very much, the camera works quite well, just not uploading the information to the spreadsheet, the ID of the spreadsheet has 44 characters right? and in the app I get this error:
It is a Samsung A21s
I used the code like this and gave it Drive API permissions.
function doPost(e) {
var ss = SpreadsheetApp.openById('1c-l5A-aSeBcsQsDz4YUc6K8XitkTfYyCLmxE4phvGq0');
var sh = ss.getSheetByName('Sheet1');
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();
var rowData = [];
rowData.push(e.parameters.itemName[0]);
rowData.push(e.parameters.itemDescription[0]);
rowData.push(e.parameters.itemValue[0]);
rowData.push(e.parameters.filename[0]);
rowData.push(fileId);
rowData.push('https://drive.google.com/file/d/' + fileId);
sh.appendRow(rowData);
return ContentService.createTextOutput('Image: ' + e.parameters.filename + ' with ID: ' + fileId + ' successfully uploaded to Google Drive' );
}```
Friend, it's working very well, thank you very much. I wanted to ask you how can I create new blocks? so I can call getASD and makeFilename, or how does it work? the same for 'to getASD' and to 'makeFilename'
It has something to do with?: HOWTO: Get Application Specific Directory -ASD (where one exists)
Thank you very much.
You need a File component, then drag out the procedure block and build the procedure. The action block for your procedure will be created in the procedure palette.
function doPost(e) {
var ss = SpreadsheetApp.openById('1jwAmuKhZOyYGTxsixkXj4QWjd4XS0maek7PnDo6cDWc');
var sh = ss.getSheetByName('Sheet2');
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();
var rowData = [];
rowData.push(e.parameters.itemName[0]);
rowData.push(e.parameters.itemDescription[0]);
rowData.push(e.parameters.itemValue[0]);
rowData.push(e.parameters.filename[0]);
rowData.push(fileId);
rowData.push('https://drive.google.com/file/d/' + fileId);
sh.appendRow(rowData);
return ContentService.createTextOutput('Image: ' + e.parameters.filename + ' with ID: ' + fileId + ' successfully uploaded to Google Drive' );
}