我正在使用jQuery Croppie lib裁剪用戶上傳的文件。當用戶上傳文件時,我打開用戶可以裁剪圖像的模式。之後,我想將這個裁剪後的圖像設置爲文件輸入值,以便用戶可以提交表單,然後當一切準備就緒時,但我不知道如何將裁剪後的圖像設置爲輸入值。注入裁剪文件作爲輸入:文件值
這是我的代碼。
$scope.openCropModal = function(files) {
if (!(files[0] instanceof Object) || (fileUploadMaxSize * 1100000) < files[0].size) {
Alertify.alert('File size must be less than ' + fileUploadMaxSize + 'mb');
return false;
}
$('#cropLogoModal').modal({});
var $uploadCrop = $('#cropperMainContainer').croppie({
viewport: {
width: 200,
height: 200,
type: 'square'
},
boundary: {
width: 300,
height: 300
},
enableExif: true,
enableOrientation: true,
orientation: 4,
});
var reader = new FileReader();
reader.onload = function (e) {
$uploadCrop.croppie('bind', {
url: e.target.result
}).then(function() {
});
};
reader.readAsDataURL(files[0]);
$('#ready').on('click', function() {
$uploadCrop.croppie('result', 'blob').then(function(blob) {
});
});
$('.vanilla-rotate').on('click', function() {
$uploadCrop.croppie('rotate', parseInt($(this).data('deg')));
});
}
您是如何發送此表單的?通過ajax或默認的HTML操作? – Kaiido
默認的HTML表單提交 – Aram810
太糟糕了...然後hackerish dataURI空字段是你唯一的方法...對於未來可以通過ajax發送的讀者,創建一個FormData對象並在其中附加你的blob版本的畫布,所以它作爲多部分應該是任何二進制數據上傳。 – Kaiido