Created
January 21, 2019 15:09
-
-
Save PeterBerthelsen/4fd076a97c0e8241b49953a0a0cb8c4b to your computer and use it in GitHub Desktop.
OrthoBot Image Processing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//////////////////////////Upload Images/////////////////////////////////////////////////////// | |
if (ImageAttachURL == 0 || ImageAttachURL == null){ //If no image URLs are listed... | |
console.log("No images detected!"); //Log no images detected | |
} else { //If image URLs are listed... | |
try{ //Attempt to upload images from URLs | |
var mediaId = new Array(0); //IDs for uploads, will be CSVs | |
var imgs = ImageAttachURL.split(","); //Split URL string into individual links | |
console.log(imgs.length + " images detected!"); //Log number of images to upload | |
for (i in imgs){ //For each image detected... | |
console.log("processing upload: " + imgs[i]); //Log the upload | |
var blob = UrlFetchApp.fetch(imgs[i]).getBlob(); //Get URL and convert to Blob format | |
var imageId = service.uploadMedia(blob); //set imageID variable to pass through .uploadMedia | |
if (imageId) { //If imageId is valid... | |
if (i == 0) { //If it's the first image... | |
mediaId = mediaId + imageId.media_id_string; //get media ID (used to tweet image) | |
} else if (i < 4) { //If it's the second, third, or fourth image | |
mediaId = mediaId + "," + imageId.media_id_string; //get media ID | |
console.log(imageId.media_id_string + " uploaded"); //log media ID number | |
} else { //If 4 images have already been added to mediaId... | |
console.log("Maximum Image (4) already attached! " + | |
imageId.media_id_string + " NOT included"); //Prevents tweet error for more than 4 images | |
} | |
} else { //If imageId is not found... | |
console.log("Image upload FAILED!"); //log failure | |
} | |
} //next image | |
console.log("MEDIA ID(s): " + mediaId); //Log number of successful uploads | |
params.media_ids = mediaId; //set media_ids to string value containing uploaded IDs | |
} catch (e) { //If image upload fails (bad URL, etc)... | |
console.log("FAILURE! Error captured: " + e); //Catch and log error | |
} | |
} //end of URL list parsing |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment