This is my first time programming with Google products so please bear with me.
I created a Google Form that accepts photos as file input and places them in Google Drive in a target folder determined by the form responses.
I started with this resource: https://developers.google.com/apps-script/samples/automations/upload-files#code.gs
My current code works fine, placing the images in the correct target folder.
I would like to convert .heic files to .jpeg so all devices can open the files. I am trying to use the function getAs("image/jpeg") for the conversion.
If I leave out the getAs() function, the .heic files get placed in the correct target folder.
When I use the getAs() function, the .heic file is placed in the default Files (File response) folder but no .jpeg is created and nothing is put in the target folder.
Note that once I figure out how to do that, I will use an if/else statement to apply the conversion to .heic files only.
Thanks in advance for your help!
...
function onFormSubmit(e) {
// Get the destination folder
var destFolder = folder_based_on_form_response; // this part works
// Get all form responses
let itemResponses = e.response.getItemResponses();
// Get the file upload response as an array to allow for multiple files
let fileUploads = itemResponses.filter((itemResponse) => itemResponse
.getItem().getType().toString() === "FILE_UPLOAD")
.map((itemResponse) => itemResponse.getResponse())
.reduce((a, b) => [...a, ...b], []);
// Move the files to the destination folder
if (fileUploads.length > 0) {
fileUploads.forEach((fileId) => {
DriveApp.getFileById(fileId).getAs("image/jpeg").moveTo(destFolder);
});
}
}
...
I believe your goal is as follows.
.heicformat to Jpeg format by modifying your script.In this case, how about the following modification? In this modification, the following flow is used.
.heicfile..heicformat to PNG format.Modified script:
From:
To:
.heicfile, the.heicfile is converted to Jpeg format and moved to the destination folder.Note:
.heicfiles, no error occurs. The.heicfiles could be converted to Jpeg format and moved to the destination folder. But, if your.heicfiles are files that cannot be converted, an error occurs. please be careful about this.