[英]how to connect base64 image and send it using multipart?
Hi I am using NgimgCrop
and i successfully got the base64 image Now I want to send it using multipart form data in http post
request. 嗨,我正在使用
NgimgCrop
并且我成功获取了base64图像现在,我想使用http post
请求中的多部分表单数据发送它。
My file upload code look something look like this 我的文件上传代码看起来像这样
scope.myCroppedImage = '';
$scope.uploadFile = function (file) {
if (file) {
// ng-img-crop
var imageReader = new FileReader();
imageReader.onload = function (image) {
$scope.$apply(function ($scope) {
$scope.myImage = image.target.result;
$scope.profileData.data = $scope.myImage;
console.log($scope.profileData.data);
});
};
imageReader.readAsDataURL(file);
}
};
Is there any way it convert it multipart after base64 in angular ? 有什么办法可以将base64之后的多部分转换为angular吗? I tried various links but nothing worked.
我尝试了各种链接,但没有任何效果。
You need to send it with FormData: 您需要使用FormData发送它:
YourAppName.config(function($httpProvider) {
$httpProvider.defaults.transformRequest = function(data) {
var fd = new FormData();
angular.forEach(data, function(key, value) {
fd.append(key, value);
});
return fd;
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.