我一直在努力弄清楚如何从服务器获取文件URL并将其显示为dropzone中的图像。我的问题是我不知道如何将该URL转换为dropzone文件对象。我已经查过了,我明白了,但是解释不是那么清楚。
下面是我的代码:$('.c-section').on('click', '.s-body-row', async function () {
// AJAX stuff
let file = res.data.file
// File syntax is { name: smthng, url: smthng }
upDropzone.emit("addedfile", { name: file.name }) // error is here
upDropzone.emit("thumbnail", { name: file.name }, file.url) // This does not run (obviously)
})
任何帮助都非常感谢!
提前感谢!
尝试以下操作:
var mockFile = {
name: 'name.jpg',
size: 12345,
type: 'image/jpeg',
status: Dropzone.ADDED,
url: 'url.com',
accepted: true
};
// Call the default addedfile event handler
myDropzone.emit('addedfile', mockFile);
//show the thumbnail of the file:
myDropzone.emit('thumbnail', mockFile, 'url.com');
myDropzone.emit('complete', mockFile);
myDropzone.files.push(mockFile);