-
Notifications
You must be signed in to change notification settings - Fork 515
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to pass crop image in form? #174
Comments
You can convert cropped image to BLOB and bind result to FormData and send result via http. function dataURItoBlob(dataURI) {
var byteString = atob(dataURI.split(',')[1]);
var mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0]
var ab = new ArrayBuffer(byteString.length);
var ia = new Uint8Array(ab);
for (var i = 0; i < byteString.length; i++) {
ia[i] = byteString.charCodeAt(i);
}
var blob = new Blob([ab], { type: mimeString });
return blob;
} and sending via http vm.uploadImage = function() {
var formData = new FormData();
var croppedImage = dataURItoBlob(vm.myCroppedImage);
formData.set("file", croppedImage, fileName);
$http.post("/image", formData, {
transformRequest: angular.identity,
headers: {
'Content-Type': undefined
}
}));
} Hope this help. :) |
Yes, Thanks. its working fine. :) |
Hi @tkehayov I got this error
When run this function (dataURItoBlob) ; Can you help me ? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have used your crop code in my project, cropping image is showing fine. But how to upload the cropped image via api?
How to pass crop image in form ?
Please help!
The text was updated successfully, but these errors were encountered: