简体   繁体   English

通过file_put_contents将base64图像发布到文件夹时,从ajax得到413请求实体太大错误

[英]getting 413 Request Entity Too Large error from ajax when posting base64 image to folder by file_put_contents

I m getting 413 Request Entity Too Large error while I sending my data by ajax I m getting converted base64 image encoded code...im passing that to My controller function in codeigniter..... that giving me error 413 Request Entity Too Large 我通过Ajax发送数据时遇到413 Request Entity Too Large错误,得到转换的base64图像编码的代码... im将其传递给Codeigniter中的我的控制器函数.....这给了我413 Request Entity Too Large的错误

my ajax code is bellow 我的ajax代码是波纹管

    $('#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...');    
                    }
                });


});

my codeigniter controller function 我的codeigniter控制器功能

    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);

                   }

    }   

If you're running on nginx, this is the likely cause 如果您在Nginx上运行,这可能是原因

In the nginx.conf 在nginx.conf中

http {
    server {
        client_max_body_size 20M;
    }
}

Increase that to a more reasonable number and do some more testing. 将其增加到一个更合理的数字并进行更多测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将图像转换为 expo 中的 base64 react-native(仅在前端):PayloadTooLargeError:请求实体太大 - convert image to base64 in expo react-native(only in the frontend): PayloadTooLargeError: request entity too large 413请求实体太大 - 413: Request entity too large 解决错误413请求实体太大 - Work around Error 413 request entity too large 请求实体太大-Google Map Directions错误413 - Request entity too large - google map directions error 413 错误:413 “请求实体太大” Html + MVC WCF 服务 - Error: 413 “Request Entity Too Large” Html + MVC WCF service 413 payload too large,对于 base64 string 在 express 中调整大小后 - 413 payload too large, for base64 string after adjusting size in express Next.js:文件上传时错误 413 请求实体太大 - Next.js: Error 413 Request Entity Too Large on file upload 通过Ajax发布Base64图像数据-数据截断 - Posting Base64 Image Data via Ajax - Data Truncating gatsbyjs function 文件上传错误 413 实体太大 - gatsbyjs function file uploading error 413 entity too large 错误:StatusCode错误:413-{“错误”:{“代码”:413,“消息”:“请求实体太大”}} - Error: StatusCodeError: 413 - {“error”:{“code”:413,“message”:“request entity too large”}}
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM