vue-upload-component
vue-upload-component copied to clipboard
How to add existing files to uploader?
Let's say I have array of files, that are coming from API. How can I correctly add them to the uploader instance?
I've found the solution, maybe it can be useful:
getRemoteBlob(remoteFile) {
return new Promise((resolve) => {
const xhr = new XMLHttpRequest();
xhr.open('GET', remoteFile);
xhr.responseType = 'blob';
xhr.onload = () => {
const file = xhr.response;
file.thumb = URL.createObjectURL(xhr.response);
this.$refs.photos.add(file);
resolve(file);
};
xhr.send();
});
},
remoteFilesToBlob(photos) {
Promise.all(photos.map(this.getRemoteBlob)).catch((e) => {
console.error('remoteFilesToBlob error', e);
});
}
It doesn't work :( I have an array of images files : [ 'https://....//image1.png', 'https://....//image2.png' ]; If I dump file xhr.response I get Blob {size: xxxx, type: "image/png"} But after this.$refs.upload.add(file); // upload is my component I can't see any images