vue-image-crop-upload icon indicating copy to clipboard operation
vue-image-crop-upload copied to clipboard

as a developer I want to upload image as object

Open hovo333 opened this issue 6 years ago • 5 comments
trafficstars

possible solution is to have overloaded function with extra parameter(flag) to upload encoded data or not

hovo333 avatar Mar 13 '19 07:03 hovo333

I found a solution. I did not set value for 'url' parameter, this means that your module will not try to upload a photo(send request). I used the @crop-success="cropSuccess" opportunity/event/parameter after clicking on the save button, in the cropSuccess function I get the photo data in the Base64 format. after that I make the necessary changes to get the photo data in the object format: for example: const url = 'data:image/png;base6....'; // photo data in the Base64 format. fetch(url) .then(res => res.blob()) .then(blob => { const file = new File([blob], "File name") })

hovo333 avatar Mar 13 '19 11:03 hovo333

How did you get the data: string from the request, I'm trying to figure that out.

DeBelserArne avatar Apr 26 '19 21:04 DeBelserArne

Hello @aFluxx I use AWS to save files. do you know what it is ? or do you just need to understand how you can get some data from the blob?

hovo333 avatar Apr 26 '19 22:04 hovo333

Not even sure what the blob is, haha :D

I was just wondering how I could get the data:image/{png,jpeg};base64 from the request. In the end I just managed to do it this way:

cropSuccess(imgDataUrl, field) {
            console.log('-------- crop success --------');
            // console.log(field);
            axios
                .post('/pigeon/' + this.id + '/avatar', {
                    image: imgDataUrl,
                })
                .then(function(response) {
                    location.reload();
                })
                .catch(function(error) {
                    console.log(error);
                });

So I removed the url prop from the component, and I did an axios request to my backend in the cropSuccess method. Here I can acces the imgDataUrl which is the base64 string

DeBelserArne avatar Apr 27 '19 05:04 DeBelserArne

@aFluxx I'm glad you found a solution

hovo333 avatar May 07 '19 15:05 hovo333