【问题标题】:Rename uploaded file so it can be removed DropZone.js重命名上传的文件,以便将其删除 DropZone.js
【发布时间】:2015-02-25 10:17:23
【问题描述】:

我决定更新这个问题,因为我仍然无法更改 imageId

这是我当前的 dropzone 实现

   $("div#UploadImage").dropzone({
            url: '@Url.Action("SaveUploadedPhoto", "Listing", new { advertId = @Model.AdvertId })',
            addRemoveLinks: true,
            init: function () {
                var myDropzone = this;
                // First change the button to actually tell Dropzone to process the queue.
                $("input[type=submit]").on("click", function (e) {
                    // Make sure that the form isn't actually being sent.
                    e.preventDefault();
                    e.stopPropagation();
                    myDropzone.processQueue();
                });
                myDropzone.on("success", function (file, rep) {

                    console.log(rep.UniqueId);
                    fileList[i] = { "serverFileName": rep.UniqueId, "fileName": rep.UniqueId, "fileId": rep.UniqueId, "name": rep.UniqueId };
                    i++;

                    console.log(fileList);
                });
                myDropzone.on("removedfile", function (file) {
                    var rmvFile = "";
                    for (f = 0; f < fileList.length; f++) {

                        if (fileList[f].fileName == file.name) {
                            rmvFile = fileList[f].serverFileName;
                        }

                    }
                    if (rmvFile) {
                        $.ajax({
                            url: '@Url.Action("DeleteUploadedFile", "Listing")',
                            type: "POST",
                            data: { "id": rmvFile }
                        });
                    }
                });
            },
            maxFilesize: 2,
            maxFiles: 12
        });

当我上传图像时,我们将图像传递给第三方公司,该公司返回该图像的唯一 ID,然后此唯一 ID 保存在我的数据库中,然后我将此唯一 ID 传回视图,该视图将成为上传的图像名称,当我这样做时,我正在尝试在上述 dropzone 实现中的“成功”函数中执行此操作

console.log(rep.UniqueId);

我可以看到值和它的正确性。

当我在 dropzone 上按“删除图像”时,会调用“removedFile”函数,这不会向控制器触发,因为 rmvFile 是旧图像名称并且它在 for 循环中找不到匹配项,我知道这是因为当我这样做时

console.log(rmvFile);  

它显示了旧名称,现在我的问题是我在这里做错了什么?如何将上传的图片名称或 id 更改为上传完成后返回的 uniqueId?所以我可以在需要时成功删除它。

我浏览了网络,尝试了导致我的成功方法目前看起来的情况。

【问题讨论】:

    标签: javascript asp.net-mvc-5 dropzone.js


    【解决方案1】:

    在尝试了许多不同的解决方案之后,我现在已经设法让它工作了。

    我发现在图片的 uniqueId 中进行了以下传递

    file.serverId['UniqueId'],
    

    【讨论】:

      猜你喜欢
      • 2016-09-10
      • 1970-01-01
      • 2012-07-28
      • 2013-10-22
      • 1970-01-01
      • 2014-01-15
      • 1970-01-01
      • 2021-12-22
      • 1970-01-01
      相关资源
      最近更新 更多