-
Uploading captured image into the specific folder server using volley library
about 9 years ago
-
about 9 years ago
Devesh,
Can you please correct my php code as per your remark in my code itself and where do i need to add base64 function
-
-
about 9 years ago
Amit & Devash,
I appreciate If you give your inputs in stackoverflow for this particular question?
-
-
about 9 years ago
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??
-
-
about 9 years ago
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_path != null) { File mFile = new File(file_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_path = path; this.isFile = true; } } }
-
-
about 9 years ago
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.
-
5 Answer(s)