使用dropzone.js使用相同的file.name上载多个文件 [英] Uploading multiple files with the same file.name using dropzone.js

查看:171
本文介绍了使用dropzone.js使用相同的file.name上载多个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在实施dropzone.js,一切都很完美,直到我尝试上传多个具有相同名称的文件,让我们说从iOS设备上传照片都是同名的:image.jpg,我可以更改文件在我的PHP代码中命名,但问题是在dropzone中不再可以访问,例如,删除上传的照片,因为我将以两个不同的名称结束一个在我的php重命名的文件中,另一个在dropzone中。

I'm implementing dropzone.js and everything is perfect until I try to upload multiple files with the same name, let's say uploading photos from an iOS device where all have the same name: image.jpg, I can change the file name in my php code but the problem is that is no longer accessible in dropzone for example, to delete a photo uploaded, because I will end with two different names one in the file renamed with my php and the other in dropzone.

那么,任何人都可以帮助我吗?有没有办法在上传js之前重命名文件?

So, anyone can help me with that? There's a way to rename the file before upload with js?

谢谢,

推荐答案

您是否正确设置了paramName?并且您需要记住,如果uploadMultiple为true,Dropzone将向此字段添加[],因此您可以通过paramName命名的数组获取值。

Did you set paramName correctly? And you need to remember that Dropzone will add [] to this field if uploadMultiple is true, so you can get the values through an array named by your paramName.

但如果你想重命名,你可以试试这个:

But if you want to rename anyway you could try this:

Dropzone.options.myAwesomeForm = {
  paramName: "file",
  uploadMultiple: true,
  parallelUploads: 1,
  //[more configuration]

  init: function() {
    var myDropzone = this;

    //[some code]

    this.on("sending", function(file, xhr, formData) {
      var name = "name-you-want-and-should-be-unique";
      formData.append(name, file);
    });

    //[some more code]
  }
}

请注意,我将parallelUploads设置为1,因此不会替换所需的名称。但是如果你想要更多,你应该通过监听事件addedfile为你添加的每个文件添加一个数据id,然后在你通过发送发送文件时把它带走。

Note that I set parallelUploads to 1 so the name you want won't be replaced. But if you do want more you should put an data-id to every file you add through listening to event "addedfile" and then take it when you send the file through "sending".

我希望你觉得它很有用:)

I hope you find it useful :)

这篇关于使用dropzone.js使用相同的file.name上载多个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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