为每个文件设置并获取uniqueID

时间:2015-07-02 06:53:23

标签: jquery jquery-file-upload

我使用JqueryFileUpload。 我怎么能得到每个文件的唯一ID ???

$('#MultiFileInput').fileupload({
  dropzone: $("#dropZone"),
  url: "./fileUpload.ashx",
  dataType: 'json',
  submit: function (e, data) {
    $.each(data.files, function (i, file) {
      alert("uid for file " + file.name + " - " + file.uid);
    }
  }
});

我必须在jquery-fileupload-5.42.3.js中修复代码:

_getSingleFileInputFiles: function (fileInput) {
  /* ----==== CODE ====-----*/
  if (!$.fileuploadid) $.fileuploadid = 1;
  $.each(files, function (index, file) {
    file.uid = "fileuploadid" + $.fileuploadid++ ;
  });
  return $.Deferred().resolve(files).promise();
}

可以访问没有代码更改源JqueryFileUpload?

1 个答案:

答案 0 :(得分:0)

var MyIncrement = 0;
$('#MultiFileInput').fileupload({
  dropzone: $("#dropZone"),
  url: "./fileUpload.ashx",
  dataType: 'json',
  submit: function (e, data) {
    $.each(data.files, function (i, file) {
      file.uid = "MyIncrement" + ++MyIncrement; //Registred uid for each file
      alert("submit file " + file.name + " - " + file.uid);
    }
  },
  done: function (e, data) {
    $.each(data.files, function (i, file) {
      alert("done file " + file.name + " - " + file.uid); //Get uid for each file
    } 
  }
});