Okay Wix Velo masters, I come to you again with another quandary. I am needing to use the getDownloadUrl() function from media-manager-backend, for every video in an array, and then generate a new array with the proper download URLs instead of the useless wix:video ones.
I’ve been at it a couple days, and in all my attempts, the closest I got was having console.log show all of them, and indeed it does, and it showed that the function was actually getting the urls I need, BUT they are not in an array. Whenever I try to put it into an array, it simply does nothing, or creates an array of empty values.
Here is the failed code as I have it currently, to show what I’m trying to achieve. I already found all the videos and put them in an array called “videoArray”, and now I just need to get the download Urls into a new array called “urlVideoArray”:
var urlVideoArray = []
videoArray.forEach(async(video) => {
video = await mediaManager.getDownloadUrl(video);
urlVideoArray.push(video)
});
console.log("urlVideoArray", urlVideoArray)
The result of the above code is just an empty array.
But when I do this:
videoArray.forEach(async(video) => {
video = await mediaManager.getDownloadUrl(video);
console.log("video", video)
});
I get this result, proving that it is getting the urls I need. But here it’s obviously just listing each one inside the “forEach” statement, as they come through:
Does anyone have any idea how I might could achieve my goal of creating a new array from the results of the getDownloadUrl function? I can’t for the life of me figure out why this isn’t working. I’ve used the forEach and .push methods elsewhere in this code when working with arrays, to create new arrays, and it works perfectly. But here it seems to have a problem with the addition of the getDownloadUrl function.
I’m sure it’s something simple I’m missing here so any help is appreciated!
Thanks,
Jared