Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Uploading captured image into the specific folder server using volley library

    • 0
    • 0
    • 0
    • 5
    • 0
    • 0
    • 0
    • 1.04k
    Answer it

    This is one of the famous question which is unanswered clearly. I have posted it on stackoverflow link as follow:

    http://stackoverflow.com/questions/33341069/uploading-captured-image-into-the-specific-folder-server-using-volley-library

    I want to upload captured image into the server with specific folder. I am not able to store image.

    It is showing .jpeg null, which means its not storing my image.Please help me where I am getting wrong?

 5 Answer(s)

  • Amit,

    Is it necessary to use multirequest. I don't what to change my entire code on volley. Its just not able to upload the image taking from camera.

    I want to know where in my code I am getting wrong??

  • Volley code to upload image on server

    package com.fartogram.utils;
    
    import java.io.File;
    
    import org.json.JSONObject;
    
    import android.content.Context;
    import android.os.Bundle;
    
    import com.android.volley.Request;
    import com.android.volley.Response;
    import com.android.volley.VolleyError;
    import com.android.volley.examples.toolbox.MultipartRequest;
    import com.android.volley.examples.toolbox.MyVolley;
    import com.android.volley.toolbox.JsonObjectRequest;
    
    public class JSONRequestResponse {
    
        public JSONRequestResponse(Context cntx) {
            mContext = cntx;
        }
    
        private final Context mContext;
        private int reqCode;
        private IParseListener listner;
    
        private boolean isFile = false;
        private String file_path = "", key = "";
    
        public void getResponse(String url, final int requestCode,
                IParseListener mParseListener) {
            getResponse(url, requestCode, mParseListener, null);
        }
    
        public void getResponse(String url, final int requestCode,
                IParseListener mParseListener, Bundle params) {
            this.listner = mParseListener;
            this.reqCode = requestCode;
    
            Response.Listener<JSONObject> sListener = new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    if (listner != null) {
                        listner.SuccessResponse(response, reqCode);
                    }
                }
            };
    
            Response.ErrorListener eListener = new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    if (listner != null) {
                        listner.ErrorResponse(error, reqCode);
                    }
                }
            };
    
            if (!isFile) {
                JsonObjectRequest jsObjRequest = new JsonObjectRequest(
                    Request.Method.GET, url, null, sListener, 
    
    eListener);
                MyVolley.getRequestQueue().add(jsObjRequest);
            } else {
                    if (file&#95;path != null) {
                        File mFile = new File(file&#95;path);
                        MultipartRequest multipartRequest = 
        new MultipartRequest(url,eListener, sListener, key, mFile, params);
                    MyVolley.getRequestQueue().add(multipartRequest);
                } 
            }
        }
    
        public boolean isFile() {
            return isFile;
        }
    
    
        public void setFile(String param, String path) {
            if (path != null && param != null) {
                key = param;
                file&#95;path = path;
                this.isFile = true;
            }
        }
    
    }
    
  • I think you are sending image as String to server.

    But your php code needs to encode the String image data.

        function base64_to_jpeg( $base64_string, $output_file ) {
            $ifp = fopen( $output_file, "wb" ); 
            fwrite( $ifp, base64_decode( $base64_string) ); 
            fclose( $ifp ); 
            return( $output_file ); 
        }
    

    Make sure you give permission to folder,

    Also

    please accept the answer if you find it solved your problem this will help other users to get proper answer to their quires.

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: