VolleyPlus
VolleyPlus copied to clipboard
File/String not uploading to server
private void sendCompanyInformationToServer() {
SimpleMultiPartRequest smr = new SimpleMultiPartRequest(Request.Method.POST, User.ADD_COMPANY,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.d("Response", response);
try {
JSONObject jObj = new JSONObject(response);
String message = jObj.getString("message");
Toast.makeText(activity, message, Toast.LENGTH_LONG).show();
} catch (JSONException e) {
// JSON error
e.printStackTrace();
Toast.makeText(activity, "Json error: " + e.getMessage(), Toast.LENGTH_LONG).show();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
handleError(error);
}
}) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> headers = new HashMap<>();
Log.d(LOG_TAG, "authorization token: " + authorization);
headers.put(Constants.XREQUESTED_HEADER_KEY, Constants.XREQUESTED_HEADER_VALUE);
headers.put(Constants.AUTHORIZATION_HEADER_KEY, "Bearer " + authorization);
return headers;
}
// @Override // protected Map<String, String> getParams() throws AuthFailureError { // Map<String, String> params = new HashMap<>(); // // params.put(User.TITLE, etOrganizationTitle.getText().toString()); // // params.put(User.PHONE, etOrganizationPhone.getText().toString()); // // params.put(User.ADDRESS, etOrganizationAddress.getText().toString()); // // params.put(User.LAT, lat); // // params.put(User.LNG, lng); // // Log.d(LOG_TAG, "Registration Token: " + authorization); // // return params; // }
};
smr.addStringParam(User.TITLE, etOrganizationTitle.getText().toString());
smr.addStringParam(User.PHONE, etOrganizationPhone.getText().toString());
smr.addStringParam(User.ADDRESS, etOrganizationAddress.getText().toString());
smr.addStringParam(User.LAT, lat);
smr.addStringParam(User.LNG, lng);
smr.addFile(User.IMAGE, ProductActivity.imageFilePath);
MyApp.getInstance().addToRequestQueue(smr);
}
Did you resolve this?
Got the same issue. Please fix it, or let us know what we are doing wrong.
@boostio funded this issue with $5. Visit this issue on Issuehunt
@larrytech7 has started working. Visit this issue on Issuehunt
@larrytech7 has stopped working. Visit this issue on Issuehunt
@AhmadullahSaikat did you check that your file path is correct? and that your server is checking for the correct name as your file upload parameter?
@amitkr936 has started working. Visit this issue on Issuehunt
@AhmadullahSaikat https://github.com/DWorkS/VolleyPlus/wiki/Multipart-Request follow this example
@1hakr has started working. See it on IssueHunt
@1hakr has rewarded. See it on IssueHunt