How to get an updated array / string data with all links in it?

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/

Hello Diego.

I’ve made a little tweak to your code. It clears and updates an array every time changes are made and stores data in the array.
OnChange triggers even if a file is removed, so it is quite handy.
Take a look at the code here and let me know if this isn’t what you’re looking for: URLs in array - CodeSandbox.

WOW, you pushed let arr = new Array; inside widget.onChange(function (group)
Got it… well, thank you :pray: I appreciate your help. You guys go above and beyond.

What should I add to this code to get file previews 140px x 140px without text, somewhere below the number of uploaded files?
Screen Shot 2022-10-18 at 9.51.44 AM

Sorry if I’m asking for too much but this would perfectly complete my UX.

Hey Diego, sorry for the delay.
I suggest you check this snippet from our docs: https://uploadcare.com/docs/uploads/file-uploader/#render-the-uploaded-image-preview.
Give it a try, and let us know if it’s working for you or not really.

1 Like

Thank you. I will try.

1 Like