在dropzone.js中分配文件服务器id
Assign files server id in dropzone.js
使用dropzone.js
,我正在为滑块上传图像。当我将文件上传到服务器时,响应只是一个与图像/文件数据库id相对应的数字。如果有一个文件列表,则有一个id列表作为响应。现在,出于某种目的,我想将此id分配给dropzone文件。
上传文件时会触发一个成功事件,请附上下面的示例代码(this
是dropzone参考(
this.on("success",
function(file, responseStr) {
console.log(responseStr);
var responseObj = JSON.parse(responseStr);
if (responseObj.success) {
// save response for later processing
file.additionalInfo = responseObj;
} else {
var message = responseObj.message;
file.previewElement.classList.add("dz-error");
file.status = Dropzone.ERROR;
var els = file.previewElement.querySelectorAll("[data-dz-errormessage]");
for (var i = 0; i < els.length; i++) {
els[i].textContent = message;
}
}
});
对于多个文件,您可以使用;多重efiles";由dropzone提供的事件,或者只遍历每个文件的响应作为下图:
this.on("success", function (file, response)
{
// if multiple files are saved the response returns all the documents
// but dropzone will fire the success event per file
// find the corresponding document based on name
if (response != null && response.Documents != null)
{
var d = response.Documents.find(x => x.FileName == file.name);
refresh = true;
dropZone.emit("thumbnail", file, d.ThumbnailBase64);
}
});
成功集预览"id";属性
myDropzone.on("success", function(file,data) {
let myfile = file.previewTemplate;
myfile.setAttribute('id',data.server_data.id);
});
删除操作时获取此id
myDropzone.on("removedfile", function(file) {
var server_file = $(file.previewTemplate);
var id = server_file.attr("id");
$.ajax({
url: your url,
type: "DELETE",
data: { "_token":_token,'id':id },
success: (data) => {
console.log(data);
},
error: function(data){
console.log(data);
}
});
});
相关文章:
- 在浏览器中打开文本文件-服务器上出现错误
- 传递来自<输入类型=“;文件“;id=“;文件“/>尽管还有一个按钮点击
- 如何在不使用<输入类型=“;文件“;id=“;fileToLoad”>
- 如何从 Node.js 访问、检索、存储和删除文件到远程文件服务器中
- 如何在 Angular 中增加 JSON 文件的 ID 号
- 从文件服务器读取 XML 文件
- 如何从外部 js 文件引用 id
- 如何从文件服务器下载文件
- 如何使用JQUERY使用AJAX将Javascript变量(从客户端)发布到PHP文件(服务器端)
- indexedDb-使用两个独立的密钥(本地和服务器ID/联机和脱机)进行保存/更新
- 学习node文件服务器为什么将createReadStream()放入createServer()中
- NodeJs中的静态HTTP文件服务器:有时外部.js和.css文件加载正常,有时加载不正常;t
- 使用ExpressJS保护静态文件服务器
- 获取具有相同服务器ID的多个userControl的clientID
- 如何将json对象保存为文件服务器端
- 学习younode教程#11 HTTP文件服务器
- 引用来自单独XUL文件的id
- 仅由文件服务器支持的浏览器应用程序中的数据
- http.文件服务器响应的mime "Content-Type"错误
- 在dropzone.js中分配文件服务器id