上传之前Dropzone JS更改文件名 [英] Dropzone JS Change Filename Before Upload

查看:359
本文介绍了上传之前Dropzone JS更改文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用



有人看到我在这里想念的吗?还是在使用Dropzone上传文件之前,有一种更好的方法来修改文件名?

解决方案

文件是HTML 5文件对象,并且其中某些属性是只读的,您可以在此处



但是,您可以为文件对象设置新属性,例如:

  myDropone.on( sending,function(file){
file.myCustomName = my-new-name + file.name;
console.log(file.myCustomName );
});

编辑:同样,文档说,推荐的在帖子正文中发送附加参数的方法动作是:

  myDropzone.on( sending,function(file,xhr,formData){
//
formData.append( filesize,file.size);
formData.append( fileName, myName);
将与POST数据一起发送文件大小。 });

希望有帮助。


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?

解决方案

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.

这篇关于上传之前Dropzone JS更改文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆