I usually use volley library for web services and now I want to send the File (i.e. image,video etc) as a parameter just like name,country,age or other parameters. Which is the most suitable ans easy way to achieve that functionality? I've tried with 'android-async-http' but i get deprecation warning at Header in "public void onSuccess(int statusCode, Header[] headers,JSONArray response)" and if I use "useLibrary 'org.apache.http.legacy'" then error shifts to "super.onSuccess(statusCode, headers, response);" line. Following is the code that 'm using. Any help will be highly appreciated.
Code:
private void sendRegisterData(String path) {
String baseUrl = AppGlobal.BaseURL+"register";
final ProgressDialog pd = new ProgressDialog(this);
pd.setCancelable(false);
pd.show();
RequestParams params = new RequestParams();
params.put("name", name_text);
params.put("country", country_text);
params.put("userType", userType_text);
params.put("email", email_text);
params.put("password", password_text);
try {
File file = bmpToFile(profileImage_bmp); // Convert bmp to File to pass as parameter
params.put("avatar", file);
} catch (FileNotFoundException e1) {
Toast.makeText(this,
"Problem updating profile! Try later.", Toast.LENGTH_SHORT)
.show();
// new SnackBar(this,
// "Problem updating profile! try later.").show();
this.finish();
} catch (IOException e) {
e.printStackTrace();
}
AsyncHttpClient client = new AsyncHttpClient();
client.post(this, baseUrl, params, new JsonHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers,
JSONArray response) {
// TODO Auto-generated method stub
super.onSuccess(statusCode, headers, response);
}
@Override
public void onProgress(long bytesWritten, long totalSize) {
// TODO Auto-generated method stub
super.onProgress(bytesWritten, totalSize);
int progressPercentage = (int) ((int) 100 * bytesWritten / totalSize);
}
@Override
public void onSuccess(int statusCode, Header[] headers,
JSONObject response) {
// TODO Auto-generated method stub
super.onSuccess(statusCode, headers, response);
Log.e("RESULT FRIEND LIST JO", response.toString() + "");
}
@Override
public void onSuccess(int statusCode, Header[] headers,
String responseString) {
// TODO Auto-generated method stub
super.onSuccess(statusCode, headers, responseString);
Log.e("RESULT FRIEND LIST", responseString.toString() + "");
}
@Override
public void onFailure(int statusCode, Header[] headers,
Throwable throwable, JSONObject errorResponse) {
// TODO Auto-generated method stub
super.onFailure(statusCode, headers, throwable, errorResponse);
// Log.e("Upload Exeption", errorResponse.toString());
}
@Override
public void onFailure(int statusCode, Header[] headers,
String responseString, Throwable throwable) {
// TODO Auto-generated method stub
super.onFailure(statusCode, headers, responseString, throwable);
}
@Override
public void onFinish() {
// TODO Auto-generated method stub
super.onFinish();
pd.dismiss();
}
});