how to get uploaded file url from data array - JS API
Please how to get uploaded file url from data array
fetch(url, {
method: "POST",
body: formData
})
.then((response) => {
return response.text();
})
.then((data) => {
// console.log(data[secure_url]);
document.getElementById("data").innerHTML += data.secure_url[i];
});-
Hi Marshall,
You can get `secure_url` of the uploaded resource by parsing the JSON response returned by the Upload API and then accessing it in the callback as `data.secure_url`. Please find a link to a sample JS Fiddle (https://jsfiddle.net/aleksandar_cloudinary/L87evasp/) which you can use as a reference. To run it please pass a file as part of the FormData on line 3, supply the name of an upload preset on line 5, and finally replace <cloud_name> with your actual cloud name as part of the URL on line 7. Upon a successful upload, the code will extract the secure_url from the response and add it to a <p> tag on the page. Please try this out and let me know how it goes.
0
Post is closed for comments.
Comments
1 comment