使用数据库中的图像填充dropzone.js删除图像的问题

Populate dropzone.js with image from the database issue removing images

本文关键字:图像 js 删除 问题 dropzone 填充 数据库      更新时间:2023-09-26

我在调用数据库后试图删除传递给dropzone.js的文件时遇到问题。

当我导航到页面并上传一个新图像,然后在不刷新页面的情况下将其删除时,一切都如预期。

以下是我当前的上传方法

 myDropzone.on("success", function (file, response) {
                    console.log(response);
                    file.serverId = response;
                });

这是在执行console.log(response)之后,响应内部的内容;

 Object { UniqueId="evgopvdjfs1w9sos3jt5"}

这是正确的。

现在,当我按下F5并刷新页面时,我用下面的片段填充dropzone,它会返回我刚刚上传的图像。

$.getJSON("/Person/GetPreviews/").done(function (data) {
        if (data.Data != '') {
            $.each(data.Data, function (index, item) {
                var UniqueId = item.ImageName;
                var mockFile = {
                    name: item.ImageName,
                    serverId: UniqueId // This is what I need to delete the image
                };
                console.log(mockFile);
                // Call the default addedfile event handler
                myDropzone.emit("addedfile", mockFile);
                // And optionally show the thumbnail of the file:
                myDropzone.emit("thumbnail", mockFile, item.ImageUrl);
                myDropzone.files.push(mockFile);
             });
          }
  });

现在,当我做console.log(mockFile)时;如下所示,同样这是正确的。

 Object { name="evgopvdjfs1w9sos3jt5", UniqueId="evgopvdjfs1w9sos3jt5"}

现在,当谈到删除文件时,这是我当前的删除功能

 removedfile: function (file) {
                console.log(file);
                $.ajax({
                    type: 'POST',
                    url: '@Url.Action("DeleteUploadedFile", "Person", new {userId= @Model.UserId})',
                    data: "id=" + file.serverId['UniqueId'],
                    dataType: 'html',
                });
                var ref;
                return (ref = file.previewElement) != null ? ref.parentNode.removeChild(file.previewElement) : void 0;
            },

现在,当我按下从数据库中删除预填充图像上的文件时,它会在上抛出一个错误

data: "id=" + file.serverId['UniqueId'], 

说它不够用,我个人看不出是怎么回事,因为两个console.log都显示了UniqueId,这让我怀疑在用图像预填充dropzone时是否遗漏了什么?

正如你所看到的,我有一个console.log(文件);在删除功能中,当点击时显示以下

 Object { name="evgopvdjfs1w9sos3jt5", UniqueId="evgopvdjfs1w9sos3jt5"}

有人能看到出了什么问题吗?

所以这个问题有点过时了。我偶然发现了它,也找到了这个答案,这对我很有帮助:

http://www.stackoverflow.com/questions/24445724/add-existing-image-files-in-dropzone

这个特殊的问题在这里得到了回答,只是指出了serverId和UniqueId之间的混淆:

https://github.com/enyo/dropzone/issues/844