Basically, now, every time I upload something via the upload widget I do complex manipulations to properly store image URLs inside an array/variable. And since you may want to add/remove one/remove all, you have to do complex array manipulations to keep record of all changes.
This is what your updated script looks like now.
/ get a widget reference
const widget = uploadcare.MultipleWidget("[role=uploadcare-uploader]");
// script modified by me. Added array logic to collect all possible links into one variable
let arr = new Array;
// listen to the “change” event
widget.onChange(function (group) {
// get a list of file instances
group.files().forEach(file => {
// once each file is uploaded, get its CDN URL from the fileInfo object
file.done(fileInfo => {
console.log(fileInfo.cdnUrl);
// script modified by me. Added array logic to collect all possible links into one variable
arr.push(fileInfo.cdnUrl);
// this was a test piece to make sure that input field trick receives vale test.onclick = function() {
document.getElementById(“trick”).value = arr;
}
// Function to change content of element
// test.onclick = function() {
document.getElementById(“trick”).value = arr;
//}
// alert(arr);
});
});
});
Is there a way to get an updated array of URLs every time I delete /add files?
That is my biggest pain point now.
I need output like this. Comma-separated URLs:
array: https://ucarecdn.com/12707070-8732-418f-a16e-b8a044f2e1f8/,https://ucarecdn.com/d33beb2b-0e5d-4e46-a048-11b91ab32dab/,https://ucarecdn.com/21926119-6ab9-4c93-bb1a-b3c95dbb1eb3/,https://ucarecdn.com/923eab94-8122-4bcd-9542-553beff39ddf/,https://ucarecdn.com/7175b610-13bf-4145-93c1-ece3193e46a1/,https://ucarecdn.com/a6eaa673-7b55-4472-b427-de0eff7d1f5e/,https://ucarecdn.com/a6e493fe-bccf-4aad-984e-1e7a66c8781a/,https://ucarecdn.com/86ff3e83-8386-4583-a9a6-adda521af8da/