上传前 Dropzone JS 更改文件名
Dropzone JS Change Filename Before Upload
我正在使用如下所示的 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,但似乎 none 我对此文件对象所做的更改仍然存在...
myDropone.on('processingfile', function(file) {
console.log(file.name) // 'Randy.png'
file.name = 'my-custom-name.png';
console.log(file.name) // 'Randy.png'
});
即使尝试在控制台中修改此文件对象,更改也不会持续存在。我快疯了...
有人看到我在这里遗漏了什么吗?或者有没有更好的方法在使用 Dropzone 上传文件之前修改文件的名称?
File 是一个 HTML 5 文件对象,如您所见,它的一些属性是只读的 here
但是,您可以为您的文件对象设置一个新的 属性,例如:
myDropone.on("sending", function(file) {
file.myCustomName = "my-new-name" + file.name;
console.log(file.myCustomName);
});
编辑:另外,文档说,在 post 动作的正文中发送附加参数的推荐方法是:
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");
});
希望对您有所帮助。
我正在使用如下所示的 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,但似乎 none 我对此文件对象所做的更改仍然存在...
myDropone.on('processingfile', function(file) {
console.log(file.name) // 'Randy.png'
file.name = 'my-custom-name.png';
console.log(file.name) // 'Randy.png'
});
即使尝试在控制台中修改此文件对象,更改也不会持续存在。我快疯了...
有人看到我在这里遗漏了什么吗?或者有没有更好的方法在使用 Dropzone 上传文件之前修改文件的名称?
File 是一个 HTML 5 文件对象,如您所见,它的一些属性是只读的 here
但是,您可以为您的文件对象设置一个新的 属性,例如:
myDropone.on("sending", function(file) {
file.myCustomName = "my-new-name" + file.name;
console.log(file.myCustomName);
});
编辑:另外,文档说,在 post 动作的正文中发送附加参数的推荐方法是:
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");
});
希望对您有所帮助。