如何从服务器获取 URL 并将其转换为有效的 Dropzone.js 文件对象?
How to get a URL from server and convert it into a valid Dropzone.js file object?
我一直在尝试弄清楚如何从服务器获取文件 URL 并将其显示为 dropzone 中的图像。
我遇到的问题是我不知道如何将 URL 转换为 dropzone 文件对象。
我查看了 this,我明白了,但解释不是很清楚。
这是我的代码:
$('.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);
我一直在尝试弄清楚如何从服务器获取文件 URL 并将其显示为 dropzone 中的图像。 我遇到的问题是我不知道如何将 URL 转换为 dropzone 文件对象。 我查看了 this,我明白了,但解释不是很清楚。
这是我的代码:
$('.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);