[英]convert image to base64 in expo react-native(only in the frontend): PayloadTooLargeError: request entity too large
[英]getting 413 Request Entity Too Large error from ajax when posting base64 image to folder by file_put_contents
我通过Ajax发送数据时遇到413 Request Entity Too Large错误,得到转换的base64图像编码的代码... im将其传递给Codeigniter中的我的控制器函数.....这给了我413 Request Entity Too Large的错误
$('#save-image-php').click(function() {
$.ajax({
type: "POST",
url: php_directory_save,
data: { base64_image: yourDesigner.getProductDataURL()},
success: function(data) {
if(parseInt(data) > 0) {
$( "#cart_pd" ).submit();
}
},
error: function() {
//alert('some error has occured...');
},
start: function() {
//alert('ajax has been started...');
}
});
});
public function saveimage(){
$base64_str = substr($this->input->post('base64_image'),strpos($this->input->post('base64_image'), ",")+1);
$decoded = '';
$decoded = base64_decode($base64_str);
$png_name = '';
$png_name = "product-".strtotime('now').".png";
$png_url = '';
$png_url = "uploaded_files/custom_image/".$png_name;
$id = $this->product_model->save($png_name);
$data = array('cust_id'=>$id);
$this->session->set_userdata($data);
$result = '';
$result = file_put_contents($png_url, $decoded);
if($id !=''){
header('Content-Type: application/json');
echo json_encode($id);
}
}
如果您在Nginx上运行,这可能是原因
在nginx.conf中
http {
server {
client_max_body_size 20M;
}
}
将其增加到一个更合理的数字并进行更多测试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.