I\'m trying upload a Image
from my Android APP to Amazon AWS S3 and I need use AWS Restful API.
I\'m using Retrofit 2
I have used Retrofit 2 resolve
and I use Body
instead of Part
for your RequestBody
in interface
@PUT("")
Call nameAPI(@Url String url, @Body RequestBody body);
and java code
// Prepare image file
File file = new File(pathImg);
RequestBody requestBody = RequestBody.create(MediaType.parse("image/jpeg"), file);
Call call = SingletonApiServiceS3.getInstance().getService().nameAPI(
path,
requestBody
);
call.enqueue(new Callback() {
@Override
public void onResponse(Call call, final Response response) {
if (response.isSuccessful()) {
// Your handling
} else {
// Your handling
}
}
@Override
public void onFailure(Call call, Throwable t) {
Toast.makeText(getContext(), "onFailure : "+t.getMessage().toString(),Toast.LENGTH_SHORT).show();
}
});