When using the Upload Widget to upload assets to your account, you might want to rename the public_id
(filename) after choosing the asset to upload. A possible use case would be changing the name based on the asset selected by an end user.
In order to achieve this, you can use the prepareUploadParams function which can be used for both signed (and then used to generate the signature as well) and unsigned uploads.
Example
var myFileName = "myName";
var myUploadWidget = cloudinary.createUploadWidget({
prepareUploadParams: function(cb, params)
{
cb({public_id: "changedName"})
},
cloudName: "demo",
uploadPreset: "myPreset",
public_id: myFileName
},
(error, result) => {
console.log(error, result)
});
document.getElementById("upload_widget").addEventListener("click",
function(){
myUploadWidget.open();
}, false);
Please note that the function can receive any of the final parameters of the upload, not only the public_id
.
Comments
0 comments
Please sign in to leave a comment.