I'm using Dropzone.js to handle uploading of files. I would really like to be able to modify the original name of the file before uploading it to S3. It would be nice to just be able to use dropzone's processing file hook like shown below, but it appears none of the changes I make to this file object persist...
myDropone.on('processingfile', function(file) {
console.log(file.name) // 'Randy.png'
file.name = 'my-custom-name.png';
console.log(file.name) // 'Randy.png'
});
Even when trying to modify this File object in the console changes do not persist. I'm losing my mind...
Does anyone see what I'm missing here? Or is there a better way to modify the name of a file before uploading it with Dropzone?
There is a renameFile option in dropzone. js that will let you change the uploaded file name. For older versions of Dropzone the option name is renameFilename .
Dropzone. js is 'a light weight JavaScript library that turns an HTML element into a "dropzone"'. Users can drag and drop a file onto an area of the page, uploading to a server. If you would like to read more how all of this works skim through the Dropzone.
File is a HTML 5 file object, and some of it's properties is read-only as you can see here
But, you can set a new property for your file object like:
myDropone.on("sending", function(file) {
file.myCustomName = "my-new-name" + file.name;
console.log(file.myCustomName);
});
Edit: Also, the documentation says, the recommended way to send aditional params in the body of the post action is:
myDropzone.on("sending", function(file, xhr, formData) {
// Will send the filesize along with the file as POST data.
formData.append("filesize", file.size);
formData.append("fileName", "myName");
});
Hope it helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With