vue-image-crop-upload
vue-image-crop-upload copied to clipboard
as a developer I want to upload image as object
possible solution is to have overloaded function with extra parameter(flag) to upload encoded data or not
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") })
How did you get the data: string from the request, I'm trying to figure that out.
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?
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
@aFluxx I'm glad you found a solution