retrofit2

How to Upload Image file in Retrofit 2

喜夏-厌秋 提交于 2019-11-26 01:59:28
问题 I have an image of postman like below. How to do the same thing in Retrofit 2. I\'ve declared the interface like this. @Multipart @POST(\"/api/Pharmarcy/UploadImage\") Call<ResponseBody> uploadPrescriptionImage( @Query(\"accessToken\") String token, @Query(\"pharmarcyRequestId\") int pharmacyRequestedId, @Part MultipartBody.Part image); 回答1: @Multipart @POST("user/updateprofile") Observable<ResponseBody> updateProfile(@Part("user_id") RequestBody id, @Part("full_name") RequestBody fullName,

Is it possible to show progress bar when upload image via Retrofit 2?

末鹿安然 提交于 2019-11-26 01:44:40
问题 I\'am currently using Retrofit 2 and i want to upload some photo at my server. I know, that older version uses TypedFile class for uploading. And if we want to use progress bar with it we should override writeTo method in TypedFile class. Is it possible to show progress when using retrofit 2 library? 回答1: First of all, you should use Retrofit 2 version equal to or above 2.0 beta2. Second, create new class extends RequestBody : public class ProgressRequestBody extends RequestBody { private

POST Multipart Form Data using Retrofit 2.0 including image

空扰寡人 提交于 2019-11-26 01:26:42
问题 I am trying to do a HTTP POST to server using Retrofit 2.0 MediaType MEDIA_TYPE_TEXT = MediaType.parse(\"text/plain\"); MediaType MEDIA_TYPE_IMAGE = MediaType.parse(\"image/*\"); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); imageBitmap.compress(Bitmap.CompressFormat.JPEG,90,byteArrayOutputStream); profilePictureByte = byteArrayOutputStream.toByteArray(); Call<APIResults> call = ServiceAPI.updateProfile( RequestBody.create(MEDIA_TYPE_TEXT, emailString),

Logging with Retrofit 2

女生的网名这么多〃 提交于 2019-11-26 01:26:26
问题 I\'m trying to get the exact JSON that is being sent in the request. Here is my code: OkHttpClient client = new OkHttpClient(); client.interceptors().add(new Interceptor(){ @Override public com.squareup.okhttp.Response intercept(Chain chain) throws IOException { Request request = chain.request(); Log.e(String.format(\"\\nrequest:\\n%s\\nheaders:\\n%s\", request.body().toString(), request.headers())); com.squareup.okhttp.Response response = chain.proceed(request); return response; } });