我正在使用croppie.js 裁剪我的图像并将其发送到服务器。但有时服务器会显示大图像的 413 错误。有没有其他方法可以在不使用 64 基本字符串的情况下将图像作为图像发送。因为来自croppie.js 的响应是以64 基字符串的形式出现的。
这是我的 jQuery 代码片段。
$('.upload-result').on('click', function (ev) {
var file = $('input[name=userfile]').val();
var uploadErrors = [];
if (file === "") {
$('.errorImgUpload').html('You did not select a file to upload').fadeIn();
uploadErrors.push("no file");
} else{
$('.errorImgUpload').fadeOut();
}
if (uploadErrors.length === 0) {
$('#doUpload span').html("Uploading...");
$uploadCrop.croppie('result', {
type: 'canvas',
size: {
width: 760,
height: 860
}
}).then(function (resp) {
var formData = new FormData($('#product_detail_images_form')[0]);
$.ajax({
url: "<?= base_url("admin_jsessID/upload_tmp/".$id); ?>",
type: "POST",
data:formData,
mimeType: "multipart/form-data",
contentType: false,
cache: false,
processData: false,
success: function (data) {
data=data.trim();
if (data === "1") {
$('input[name=userfile]').val("");
$uploadCrop.croppie('bind', {
url: ""
});
load_uploaded_images();
$('.doneImgUpload').html('Image Successfully Uploaded.').fadeIn();
$('html, body').animate({
scrollTop: $(".doneImgUpload").height()-20
}, 200);
setTimeout(function () {
$('.doneImgUpload').fadeOut();
}, 5000);
}else if (data === "2"){
$('.errorImgUpload').html('Image Upload Failed.').fadeIn();
$('input[name=userfile]').val("");
$('html, body').animate({
scrollTop: $(".errorImgUpload").height()-20
}, 200);
setTimeout(function () {
$('.errorImgUpload').fadeOut();
}, 5000);
}else if (data === "3"){
$('.errorImgUpload').html('Image Upload Failed.').fadeIn();
$('input[name=userfile]').val("");
$('html, body').animate({
scrollTop: $(".errorImgUpload").height()-20
}, 200);
setTimeout(function () {
$('.errorImgUpload').fadeOut();
}, 5000);
}
else if (data === "0"){
$('.errorImgUpload').html('Upload Image Limit Exceeded.').fadeIn();
$('input[name=userfile]').val("");
$('html, body').animate({
scrollTop: $(".errorImgUpload").height()-20
}, 200);
setTimeout(function () {
$('.errorImgUpload').fadeOut();
}, 5000);
}
$('#doUpload span').html("Upload Image");
}
});
});
}
});