Is there any way to attached multiple images in one multipart request? The images is dynamic based on the number of images that user has picked.
Below code only works for single image:
Interface:
@Multipart
@POST("/post")
void createPostWithAttachments( @Part("f[]") TypedFile image,@PartMap Map<String, String> params,Callback<String> response);
Implementation:
TypedFile file = new TypedFile("image/jpg", new File(gallery.sdcardPath));
Map<String,String> params = new HashMap<String,String>();
params.put("key","value");
ServicesAdapter.getAuthorizeService().createPostWithAttachments(file,params, new Callback<String>() {
@Override
public void success(String s, Response response) {
DBLogin.updateCookie(response);
new_post_text.setText("");
try {
JSONObject json_response = new JSONObject(s);
Toast.makeText(getApplicationContext(), json_response.getString("message"), Toast.LENGTH_LONG).show();
if (json_response.getString("status").equals("success")) {
JSONObject dataObj = json_response.getJSONObject("data");
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
startActivity(intent);
finish();
} else {
Log.d(TAG, "Request failed");
}
} catch (Exception e) {
Log.d(TAG, e.getMessage());
}
}
@Override
public void failure(RetrofitError retrofitError) {
Toast.makeText(getApplicationContext(), retrofitError.getMessage(), Toast.LENGTH_LONG).show();
}
});