When using the Upload Widget to upload files to your account, you might want to rename the public_id (filename) after choosing the file to upload. A possible use case would be changing the name based on the file chosen by the end-user.
In order to achieve this, you can use theprepareUploadParams
function. This function can be used for both signed (and then used to generate the signature as well) and unsigned uploads.
For 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.
For more info on the prepare function (in the signed upload section): https://cloudinary.com/documentation/upload_widget#signed_uploads
Comments
0 comments
Please sign in to leave a comment.