vue-upload-component icon indicating copy to clipboard operation
vue-upload-component copied to clipboard

How to add existing files to uploader?

Open outOFFspace opened this issue 5 years ago • 2 comments

Let's say I have array of files, that are coming from API. How can I correctly add them to the uploader instance?

outOFFspace avatar Feb 11 '20 07:02 outOFFspace

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);
    });
}

outOFFspace avatar Feb 11 '20 08:02 outOFFspace

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

philchass avatar Jan 25 '21 13:01 philchass