我使用ngImgCrop插件進行圖像裁剪併發布到我的休息服務。 HTML是這樣的:在AngularJS中將base64轉換爲圖像文件
<form>
<button class="btn btn-default fileUpload" type="submit"><span>from pc</span>
<input type="file"
id="fileInput"
class="upload"
onchange="angular.element(this).scope().uploadFile(this.files[0])"/></button>
<button class="btn btn-default" type="submit">from camera</button>
<div class="cropArea">
<img-crop image="image.myImage" result-image="image.myCroppedImage"></img-crop>
</div>
<div class="hidden"><img ng-src="{{image.myCroppedImage}}" ng-model="updatedPhoto" /></div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal" ng-click="closeThisDialog(value)">Close
</button>
<button type="submit" ng-click="updatePhoto()" class="btn btn-primary">Save</button>
</form>
而且controller.js:
$scope.updatePhoto = function() {
var updatedPhotoLink = {
file: file
};
$http({
method: 'POST',
data: updatedPhotoLink,
url: '//myapiservices.com/upload'
}).then(function successCallback(response) {
console.log(response);
}, function errorCallback(response) {
console.log("error");
// called asynchronously if an error occurs
// or server returns response with an error status.
});
}
是的,它的工作原理,但通過的base64但API鏈接圖像鏈接回想把它按文件。
我試圖增加對改變這一點:
var imageBase64 = $scope.image.myCroppedImage;
var blob = new Blob([imageBase64], {type: 'image/png'});
但其沒有工作,鏡像文件恢復到空白。如何將base64 url轉換爲文件?謝謝。
不,我需要圖像文件。 – Karmacoma