|
|
|
@ -1,19 +1,5 @@
|
|
|
|
|
function upload(options) {
|
|
|
|
|
options.enctype = "multipart/form-data";
|
|
|
|
|
options.processData = options.contentType = false;
|
|
|
|
|
var data = options.data,
|
|
|
|
|
formData = new FormData();
|
|
|
|
|
for (var key in data) {
|
|
|
|
|
var val = data[key];
|
|
|
|
|
if (!Array.isArray(val))
|
|
|
|
|
formData.append(key, val);
|
|
|
|
|
else {
|
|
|
|
|
for (var i = 0; i < val.length; ++i)
|
|
|
|
|
formData.append(key, val[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
options.data = formData;
|
|
|
|
|
ajax.post(options);
|
|
|
|
|
function createObjectURL(file) {
|
|
|
|
|
return (window.URL || window.webkitURL).createObjectURL(file);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function fileInput(conf) {
|
|
|
|
@ -55,7 +41,7 @@ function fileInput(conf) {
|
|
|
|
|
|
|
|
|
|
getURLs:function() {
|
|
|
|
|
try {
|
|
|
|
|
return obj.files.map(file => (window.URL || window.webkitURL).createObjectURL(file));
|
|
|
|
|
return obj.files.map(file => createObjectURL(file));
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
@ -101,10 +87,59 @@ function uploadSupport(selector) {
|
|
|
|
|
for (var i = 0; i < length; ++i) {
|
|
|
|
|
var file = files[i];
|
|
|
|
|
file.id = "file-" + new Date().getTime() + "-" + i;
|
|
|
|
|
file.url = (window.URL || window.webkitURL).createObjectURL(file);
|
|
|
|
|
file.url = createObjectURL(file);
|
|
|
|
|
array.push(file);
|
|
|
|
|
}
|
|
|
|
|
fileset.setData(array);
|
|
|
|
|
});
|
|
|
|
|
return fileset;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var download = {
|
|
|
|
|
filename: (str) => {
|
|
|
|
|
if (str.indexOf("filename=") < 0)
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
let regexp = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/,
|
|
|
|
|
matches = regexp.exec(str);
|
|
|
|
|
|
|
|
|
|
return matches && matches[1] ? matches[1].replace(/['"]/g, "") : null;
|
|
|
|
|
},
|
|
|
|
|
_init: options => {
|
|
|
|
|
options.cache = false;
|
|
|
|
|
options.xhrFields = {responseType: "blob"};
|
|
|
|
|
options.success = (data, msg, xhr) => {
|
|
|
|
|
let disp = xhr.getResponseHeader("Content-Disposition"),
|
|
|
|
|
filename = download.filename(decodeURIComponent(disp)),
|
|
|
|
|
link = document.createElement("a");
|
|
|
|
|
link.href = createObjectURL(new Blob([data]));
|
|
|
|
|
link.download = filename;
|
|
|
|
|
link.click();
|
|
|
|
|
};
|
|
|
|
|
return options;
|
|
|
|
|
},
|
|
|
|
|
get: function(options) {
|
|
|
|
|
ajax.get(download._init(options));
|
|
|
|
|
},
|
|
|
|
|
post: function(options) {
|
|
|
|
|
ajax.post(download._init(options));
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function upload(options) {
|
|
|
|
|
options.enctype = "multipart/form-data";
|
|
|
|
|
options.processData = options.contentType = false;
|
|
|
|
|
var data = options.data,
|
|
|
|
|
formData = new FormData();
|
|
|
|
|
for (var key in data) {
|
|
|
|
|
var val = data[key];
|
|
|
|
|
if (!Array.isArray(val))
|
|
|
|
|
formData.append(key, val);
|
|
|
|
|
else {
|
|
|
|
|
for (var i = 0; i < val.length; ++i)
|
|
|
|
|
formData.append(key, val[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
options.data = formData;
|
|
|
|
|
ajax.post(options);
|
|
|
|
|
}
|