4

I want to upload an image and put the image's url into database (post_image column).

I always get error 500, every time I tried to upload an image from Android.

Here is my Android code:

private void postTimelineData(final String post_image, final String post_description, final String post_restaurant_detail, final String user_id) {
        showProgressDialog();
        String postUrl = Utils.url + "post/insert_post/" + post_description + "/" + post_restaurant_detail + "/" + user_id;
        System.out.println("postUrl: " + postUrl);
        StringRequest strReq = new StringRequest(Request.Method.POST, postUrl, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                System.out.println("Response: " + response);
                try {
                    hideProgressDialog();
                    Toast.makeText(Photo.this, "Your Image is posted!", Toast.LENGTH_SHORT).show();
                } catch (NullPointerException e) {
                    Utils.errorHandler(null, toolbarView, false);
                    hideProgressDialog();
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {
                Utils.errorHandler(volleyError, toolbarView, false);
                hideProgressDialog();
            }
        }) {
            @Override
            protected Map<String, String> getParams() {
                // Posting params to register url
                Map<String, String> params = new HashMap<String, String>();
                String postUrl = Utils.url + "post/insert_post/" + post_image + "/" + post_description + "/" + post_restaurant_detail + "/" + user_id;
                params.put("post_image", post_image);
                params.put("post_description", post_description);
                params.put("post_restaurant_detail", post_restaurant_detail);
                params.put("user_id", user_id);
                return params;
            }
        };
        strReq.setRetryPolicy(new DefaultRetryPolicy(30000, 0, 1f));
        AppController.getInstance().addToRequestQueue(strReq);
    }

CI code:

function insert_post($post_description, $post_restaurant_name, $user_id){
            $config['upload_path'] = './uploads/';
            $config['allowed_types'] = 'gif|jpg|png';
            $config['max_size'] = '1024';
            $config['max_width']  = '1024';
            $config['max_height']  = '1024';

            $this->load->library('upload', $config);

            if ( ! $this->upload->do_upload())
            {
                $error = array('error' => $this->upload->display_errors());
                echo json_encode($error);
            }
            else
            {
                $upload_data = array('upload_data' => $this->upload->data());
                $post_image = base_url() .'uploads/'. $uploadData['file_name'];
                echo json_encode($post_image);
            }

            $data = $this->post_model->insert_post($post_image, $post_description, $post_restaurant_name, $user_id);
        }

Can anyone tell me, how to fix this problem? I appreciate your help.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Damian
  • 41
  • 1
  • 2
  • 5
  • Possible duplicate of [Upload an image using Google Volley](http://stackoverflow.com/questions/29430599/upload-an-image-using-google-volley) – Anirudha Agashe May 17 '16 at 07:00
  • @Damian you are just sending string values to the server and trying them to upload? Where is your android side code to send the image file? – Tejashwi Kalp Taru Aug 27 '18 at 13:48

0 Answers0