vue-dropzone icon indicating copy to clipboard operation
vue-dropzone copied to clipboard

Cant add Src with blob url or base64

Open rickyanwar opened this issue 4 years ago • 3 comments

I am trying to add image manually but when using blob URL is not append in src, when I add ektension name ex let url = window.URL.createObjectURL(new Blob([res.data])) +'.jpg' its apppend in src

this,my code


 images.map(image => {                  
                    console.log(image.id)
                    this.$axios.get(this.$api_url + '/images/' + image.id, {
                                responseType: 'arraybuffer'
                        }).then(res => {
                            console.log(res)
                        let url = window.URL.createObjectURL(new Blob([res.data]))
                        let file = {
                            size: 123,
                            name: "Icon",
                            type: "image/png",
                        };
                        console.log(file)
                        this.images.push({
                            src: url,
                            id: image.id
                        });
                        this.$refs.imgDropzone.manuallyAddFile(file, url)
                       
                    })
                    
                })

image

rickyanwar avatar May 30 '20 01:05 rickyanwar

I have the same problem

mahyar33 avatar Jun 07 '20 15:06 mahyar33

same problem here, any solution?

helderferrari2 avatar Jun 30 '20 23:06 helderferrari2

Hello, old one... but I found a solution.

Move on to rowanwins/vue-dropzone v3.7 so that base64 dataUrl will be accepted when manuallyAddFile :

npm install https://github.com/rowanwins/vue-dropzone.git#v3.7 --save

Then you can use the kind of function below to convert your blob to a base64 dataUrl with a FileReader : https://stackoverflow.com/a/30407959/243996

const blobToDataURL = (blob, callback, ...params) => {
    const fileReader = new FileReader();
    fileReader.onload = function (e) { callback(e.target.result, ...params); };
    fileReader.readAsDataURL(blob);
};

The thumbnail will accept and use the base64 URL to display your previews.

franck-grenier avatar Sep 02 '21 16:09 franck-grenier