Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
728 views
in Technique[技术] by (71.8m points)

ruby - Multipart Image upload Retrofit Android

want to make api call in android retrofit in the following form, what is the way of sending multipart images in the following format enter image description here

my problem is when I try to send this request get unable to return parcel due to could not find or build blob: expected attachable error from the server but its fine on the postman, problem arise when I try to send images from retrofit in android

question from:https://stackoverflow.com/questions/65886357/multipart-image-upload-retrofit-android

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Try this

INTERFACE
@POST("/Your ENDPOINT")
public Call<ResponseBody> sendImages(@Body body: RequestBody)

MAKE YOUR BODY

MultipartBody.Builder builder = new MultipartBody.Builder().setType(MultipartBody.FORM)
                .addFormDataPart("order_id",orderId)
                .addFormDataPart("return_attributes[qr_code]",qrCode)
                .addFormDataPart("return_attributes[reason]","100")
                .addFormDataPart("return_attributes[description]","(31/12/2020 13:30:00)");

    for (File file:listFiles){
        builder.addFormDataPart("return_attributes[images]",file.getName(),
                RequestBody.create(MediaType.parse("image/*"),
                        file.getAbsolutePath()));
    }

BUILD AND ENQUEUE YOUR REQUEST

RequestBody body=builder.build();

Service service = retrofit.create(ApiAlfa.class);
ApiAlfa.sendImages(body).enqueue(...);

you can see this too


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...