jquery - 获取上传图片的原始base64文件名(Dropzone)

标签 jquery dropzone.js

如何获取上传图像的原始文件名。 上传后,我的意思是一旦图像被裁剪为 Dropzone 内的缩略图。我只能获取裁剪图像的base64字符串,而不是我需要图像的原始base64字符串。

这是我的一些代码:

var myDropzone = new Dropzone(document.body, { // Make the whole body a dropzone
                url: "/target-url", // Set the url
                parallelUploads: 20,
                previewTemplate: previewTemplate,
                uploadMultiple: true,
                autoQueue: false, // Make sure the files aren't queued until manually added
                previewsContainer: "#previews", // Define the container to display the previews
                clickable: ".fileinput-button", // Define the element that should be used as click trigger to select files.
                init: function() {
                    this.on("addedfile", function(file) {

                        console.log(file.name);

                    });
                }

            });

这给了我正常的文件名,而不是上传图像的base64字符串。

有人知道怎么做吗?

任何帮助将不胜感激!

最佳答案

该参数是一个 HTML5 File目的。
预览文件可以通过(在您的 init 函数内)访问:

file.previewElement

可以通过以下方式访问base64编码文件:

var reader = new FileReader();
// Closure to capture the file information.
reader.onload = function(e) { 
    //get the base64 url
    var base64URL = e.target.result;
    //print to console
    console.log(base64URL);  
};
// Read in the image file as a data URL.
reader.readAsDataURL(asdf);

关于jquery - 获取上传图片的原始base64文件名(Dropzone),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30697093/

相关文章:

javascript - 使用不带表单的 dropzone.options

javascript - 如何使用 js 或 jQuery 添加不同 div 类的值

javascript - 解析该网站的正确方法是什么?

javascript - 将 jquery-ui 回调连接到其处理程序类

javascript - 上传前 Dropzone JS 更改文件名

javascript - ASP.Net MVC 中的简单 Dropzone 实现 - 如何获取 Controller 中的数据?

javascript - 用于选择多个文件的 Dropzone 事件

javascript - 使用删除功能将自动完成 TextView 中的选定值添加到 div

javascript - 如何在 jquery 提交之前执行我的函数,直到验证正确

javascript - Dropzone.js 上传 Base64 字符串