I am trying to send images to a server. Here are my server side php variable names provided to me by the script:
$value1 = $_POST["value1"]; // string value
$value2 = $_POST["value2"]; // string value
$img_1 = $_FILES["fileToUpload1"]["name"]; // image file
$img_2 = $_FILES["fileToUpload2"]["name"]; // image file
and here is my code for placing the values -
RequestBody fileBody = RequestBody.create(MediaType.parse("image/png"), path.toString());
RequestBody fileBody1 = RequestBody.create(MediaType.parse("image/png"), path.toString());
Call<uploadResponseModel> call = adapter.uploadValues("test1","test2",fileBody1,fileBody);
call.enqueue(new Callback<uploadResponseModel>() {
@Override
public void onResponse(Response<uploadResponseModel> response, Retrofit retrofit) {
Log.i("TAG", "retro onResponse :" + response.body().getResponse().getStatus());
}
@Override
public void onFailure(Throwable t) {
Log.i("TAG", "retro onFailure :" + t.getCause());
}
});
adapter class:
public interface RetrofitAdapter {
@Multipart
@POST("/TestApp/img_upload.php")
Call<uploadResponseModel> uploadValues(@Part("value1")String value1,@Part("value2")String value2,@Part("fileToUpload1") RequestBody file1,@Part("fileToUpload2") RequestBody file2);
}
Both string values are published to the server, but not images. Please correct me if I am mistaken in publishing image files. I am new to modernization.
source
share