如何获取上传图像的原始文件名。 上传后,我的意思是一旦图像被裁剪为 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/