square / retrofit

A type-safe HTTP client for Android and the JVM
https://square.github.io/retrofit/
Apache License 2.0
43.1k stars 7.3k forks source link

Multipart upload file alongside an object throwing error in server #2481

Closed cristian1703 closed 7 years ago

cristian1703 commented 7 years ago

So I am trying to make a PUT request to upload a image and an object. Everything seems ok ( except maybe the fact that the content-type for the object is application/json instead of multipart/form-data) but the server does not receive any data. On the server side I use laravel and PHP. In my app:

`MultipartBody.Part profilePictureBody = null;
        //Initialize and populate userDetailsRequest object to create the expected json format for PHP
        UserDetailsRequest userDetailsRequest = new UserDetailsRequest();
        userDetailsRequest.setUserDetails(userDetails);//
        // RequestBody requestBody = RequestBody.create(MediaType.parse("multipart/form-data"), profilePicture);

        if (profilePicture != null){
            profilePictureBody = MultipartBody.Part.createFormData(
                    "profile_picture",
                    profilePicture.getName(),
                    RequestBody.create(MediaType.parse("multipart/form-data"), profilePicture));
        }

        final Call<ResponseBody> res = apiService.putUserDetails("multipart/form-data", userDetails, profilePictureBody);

        res.enqueue(new Callback<ResponseBody>() {
            @Override
            public void onResponse(Call<ResponseBody> call, retrofit2.Response<ResponseBody> response) {
                if (response.isSuccessful()){
                    String responseBody = response.body().toString();
                    if (response.body() != null){
                            new SweetAlertDialog(context, SweetAlertDialog.SUCCESS_TYPE)
                                    .setTitleText("Success")
                                    .setContentText("Account details saved!")
                                    .setConfirmText("Ok")
                                    .show();
                            back.onResponse(call, response);

                    }
                    else {
                        new SweetAlertDialog(context, SweetAlertDialog.ERROR_TYPE)
                                .setTitleText("Server Error")
                                .setContentText("Could not run the request. Please try again later.")
                                .setConfirmText("Ok")
                                .show();
                        back.onFailure(call, null);
                    }
                }
            }

            @Override
            public void onFailure(Call<ResponseBody> call, Throwable t) {
                new SweetAlertDialog(context, SweetAlertDialog.ERROR_TYPE)
                        .setTitleText("Server Error")
                        .setContentText("Could not run the request. Please try again later.")
                        .setConfirmText("Ok")
                        .show();
                back.onFailure(null, t);
            }
        });`

`@Multipart
    @PUT(BuildConfig.BASE_API_VERSION + "main/users/user-details")
    Call<ResponseBody> putUserDetails(@Header("Content-Type") String contentType, @Part("user_details") UserDetails userDetails, @Part MultipartBody.Part imageFile);`

My OkHttpinterceptor:

`Gson gson = new GsonBuilder()
                .setDateFormat("yyyy-MM-dd HH:mm:ss")
                .excludeFieldsWithoutExposeAnnotation()
                .setLenient()
                .create();

        Retrofit.Builder builder = new Retrofit.Builder()
                .baseUrl(BuildConfig.BASE_API_URL);

        HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
        loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.HEADERS);
        loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
        OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
        httpClient.addInterceptor(loggingInterceptor);

        if (token != null){
            httpClient.addInterceptor(new Interceptor() {
                @Override
                public Response intercept(Chain chain) throws IOException {
                    Request original = chain.request();

                    //Make a copy of the okhttp builder
                    Request.Builder requestBuilder = original.newBuilder()
                            .header("Authorization", "Basic " + token);
                    Request request = requestBuilder.build();

                    return chain.proceed(request);
                }
            });
        }
        builder.client(httpClient.build());

        builder.addConverterFactory(GsonConverterFactory.create(gson));
        Retrofit retrofit = builder.build();

        apiService = retrofit.create(MainInterface.class);`

My REQUEST looks like this:

`D/OkHttp: --> PUT http://test.dev.com/api/v1/main/users/user-details http/1.1
    I/Choreographer: Skipped 167 frames!  The application may be doing too much work on its main thread.
    D/OkHttp: Content-Type: multipart/form-data
    D/OkHttp: Content-Length: 15878
    D/OkHttp: --965ee1a1-6194-4fc7-93ff-d444218f05bc
    D/OkHttp: Content-Disposition: form-data; name="user_details"
    D/OkHttp: Content-Transfer-Encoding: binary
    D/OkHttp: Content-Type: application/json; charset=UTF-8
    D/OkHttp: Content-Length: 262
    D/OkHttp: {"email":"email@test.com","first_name":"Name","last_name":"Last Name","profile_picture":"http://cristian.dev.app.merchantproxy.com/uploads/http://cristian.dev.app.merchantproxy.com/uploads//uploads/197571179.jpg","timezone":"US/Eastern","username":"super_admin"}
    D/OkHttp: --965ee1a1-6194-4fc7-93ff-d444218f05bc
    D/OkHttp: Content-Disposition: form-data; name="profile_picture"; filename="merchant_proxy_logo.png"
    D/OkHttp: Content-Type: multipart/form-data
    D/OkHttp: Content-Length: 15180
    D/OkHttp: ?PNG
    D/OkHttp: 
    D/OkHttp: ??????IHDR??????????????????ki???????tEXtSoftware??Adobe ImageReadyq?e<????#iTXtXML:com.adobe.xmp??????????<?xpacket begin="?" id="W5M0MpCehiHzreSzNTczkc9d"?> <x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core 5.5-c021 79.154911, 2013/10/29-11:47:16        "> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"> <rdf:Description rdf:about="" xmlns:xmp="http://ns.adobe.com/xap/1.0/" xmlns:xmpMM="http://ns.adobe.com/xap/1.0/mm/" xmlns:stRef="http://ns.adobe.com/xap/1.0/sType/ResourceRef#" xmp:CreatorTool="Adobe Photoshop CC (Macintosh)" xmpMM:InstanceID="xmp.iid:BF766579FEA311E5999EF241EC438CA9" xmpMM:DocumentID="xmp.did:BF76657AFEA311E5999EF241EC438CA9"> <xmpMM:DerivedFrom stRef:instanceID="xmp.iid:BF766577FEA311E5999EF241EC438CA9" stRef:documentID="xmp.did:BF766578FEA311E5999EF241EC438CA9"/> </rdf:Description> </rdf:RDF> </x:xmpmeta> <?xpacket end="r"?>P???????7?IDATx??}?U?????w{??$$!????EA?^????|<?/???b4??"?E?4i!?$?6e?!?l???3?nf'3?9s?&_>C??s????~?R??H???`0?@???`0&??`0?0???`0&??`0?0?   ??`0L ??`0?0?   ??`0L ??`a0??`0L ??`a0??`0?@???`0??`0?@???`0&??`0?0???`0&??`0?0?    ??`0L ??`0?0?   ??`0L ??`a0??`0L ??`a0??`0?@??`a0??`0?@???`0&??`0?@???`0&??`0?0?    ??`0&??`0?0cH??jE???r?XrQ?X?b?],]?l?Y???WhSr$?O?b?K1¸?b?X>????r??;?V?(?o??
    D/OkHttp: ??}??f4=?r*????|_,_7<???rQ??4M,?"??@???wE?X?Y??\?h?0],??[>????5|???]?r??!?:??d???
    D/OkHttp: k)??/??X?,???_K???w???O?k'Q!%???t?s#?r?c?1?o?`?8?T??;?DC??X??!b9?t?$_????1??c??$?iT????)??@.?s?X?R?#?Z??X??M? ?:A ??O????6?%?C#????hWg)????|?????P,???^?l6?-?????A???z?&e????N???],?? ?c???a}t?v?wj&??5?????p^q????R??/OUq?X?'??=??6???l?TG?eg?m?w??z??w???b?K4?<???8??k??r?wH?s???Gkk?eI?Kf:#??????5???P?X   C???R???/QU0S^?}??XV1?l[|2???RO?????    ??@?i?c>?|?e???h?Q?R??M??n?`?G?d???pG?F???%??(????L?:??^?KTq\)?WC???He????~??D?^a},??J??i??Z??8??????K????n?87c?j?k??QXD???|???NZa???2??;??RY?C?o?^??9????K4?j?Gc???s?u?h?2yM?Dr???????W??#?????v],???'|9??????wE?w????%?8T^???"??  ????%d??0)???O?b????A^??"?j?b?)d??kl??'?Bkk?q?F?Yb?-?{???u???????>Iul}  t?WL???uV???U9???`?mos4?D-%
    D/OkHttp: ????R?$<VqR?uR?Zp#i?'<o(???i?[???3??
    D/OkHttp: ???y?<AQZ:??f????A?HC?*?v???-????(?????h?L?rq?;??????b?$  ??<E???a?$?? 5??X????>+-?JH???0?.???q?e?X???+??"?q??o?????$????U?%?}????y?T w??z????`??y???????/I+%]]L ???????F?y?F??'5? d?b???q?s???w?A?Af???:aL$??+#$LSz@,kB??xO???|???h?o^?"?t2????!??D??Hn?@??M(?l??7(8?Y)?À????4???Y)???E8$1??W????g?u?*@?H?_b?,?+?????B??\q?O?s??????r?|?W?%??b??7???/rc?}?x?_U7??VH?$&?!?G-?[?jQ??
    D/OkHttp: 453??B????)??8??Qy??f_?L?ci???u??GX/?OZ????$????-??Z8???&??>b?mI??]??V?????k1?[??r??mT??{$|??6&??Ka9??S?P???:???J??I??X
    D/OkHttp: O??b_??7d??????H?VX`pO?xnO? ;?4???8?c ?qR[???(?????K5???8)????????}??W+kw?RRX?L\?FFZau?"??Sx??3?{??/?Gn??,?'??R?h?a??$>?!?????;h????>??8@Z6&???>6n??~r{?E??i?`|??????????<6??(?b?ei]??n??c??M?R?/?K?i??bj*l*?S??B?S??Bo????,?.I?????chjgY?Y'a?'\0a??7????oj?K??????vi????R??\Sp{}??b4/P?ne??c?iH
            D/OkHttp: .?Y??#?O
        D/OkHttp: ?iAT????a???<l?8??7?L C<?'Yn?c?&R??grv??ra??{???????t???jv?M???k?c:?*?????0?m??|???-Z??Z%?????/?D(??orc*|???K??K??&???`p?p7#p????_?B3i#S??7???1L?E?'?k?9S?? ?0???j?\?M:???e1d;|????c ?qnA???$?)??F:?????????C?????2????fa?w?a?CUXVn??
    D/OkHttp: ??G1?-?@?????(?&usJ?M?m??{??D??sn?=?~L?9?
            D/OkHttp: ?????$???;#??I??c?X?4?? ????+???Y????.??x??   ?}L???? ???Sc<?^ 9?{?#???k??>?W$Q"??v1?x'?%2????E 0?l;?U???
    D/OkHttp: ?*,??TW?L?y?;?r?;=`??T?JX6?>
    D/OkHttp: N?I???.?x,?0??A??Dc}?????=?8d? ??????()??|???;+??~?$/h?E9f6?9???/???u????8@!lMb,?Q?$?{??J???\B
    D/OkHttp: Ad5??????_j???m??3??Vt^?WE ??R???+q?H<? ??m??O?9?s?m???2?l?}d4L?fm?J_?7???fe?F ~???vx?t?@???}?9&????w??oK???qj??jpa1??z?WN??=?2???Ti?~g???#?_IKm?$???^???>U)????!}:?oI??u???b?2??C?"???&j?-????I??l???L?~?F?_?x???u?h?E?W?????r??;h?W?O???u????g?y1????????C?y??H@???&-iV?Y???p]+??*IbaBM??_?OgVMv?b???)?u?R????{?O????K?c?I???   RO?j;?\?,???%n?#hQ?a??k?'-?fT?6?Zi  ??u???S
    D/OkHttp: }?cc????:??????(?}-???`????7?????*=?cd6????^j?_XV(????i?????}~?GHK-??DV????W?V?????+UR?\?{5?  ?r???L
    D/OkHttp: ?N??p9??l=[a?~0??w3??T[XK?r???T   !??m??x????N?y_??Q:????y"?uTbH=^aE?5F?,?AD?y!/?p=??:#
    D/OkHttp: ???.?}I?M?`8?:??BG?&n?c&±????;?Zm?_h?;K?*??????Y?+???O?;??2?!???w???b:th\??knp?T??]?U=M???B7mJ?9-?jn?
    D/OkHttp: ?{?z+?H?)?q?iG%Kg??KT??]?*L???>?{?
    D/OkHttp: Ou?K???Lj?/_0??a1?>?????=???
    D/OkHttp: ??????6iCr?F?o2??K???N?1?9?jy?????SX???/?3?*?.{ ?scl??;?1?|???qGH$j}Rf??4?Tj?U??'??=L????kM?.?t??L?U4????r`?kR?ip??6L?? {%??T??
    D/OkHttp: ?Ki?nV?(?????h???B?d?_?Q???i?W?;???)?Q????nK??&
    D/OkHttp: ?????????????
    D/OkHttp: 6?????????_"e?C?<%??)?????????\?1
    D/OkHttp: ????Y#?xpe?t??+?E.a?????W????*???(<??v?5[m?Q<'??)T?;?z?D  vJahr?#,??A??X?sz?Wa??W&??Z4??sA?d]?@?T??:??_??Z-???;?6"??r?4)????8 g????>%?R?_???(x??+?W?
    D/OkHttp: ?#?????x??6?re??u^?srP???4?uU??'?????U</]?v?R)???'????R?9?dF[p?z1?3??8Iq?{*???C qzH??%???'??j??:f'j???y?3?r??8)?:!o[W?M??\??|??<V"??<T??~???PA.???s_a??B??J)x??B!?Z?x?0?>w????U??t;??:?B?_C???u>&???/?????kf??T?"$u???A???@d??    yT??5??cC?tU??J???_?V??=??????a9?Hc???4??w?|?P?
            D/OkHttp: ?S?;q?@[WO?????~av????+?  ????*?#gk,?\??T$???c?J
            D/OkHttp: .^?;?0]C?9k?@??
            D/OkHttp: ???\$-?0??&?ap"??>d?}^????'??=Vs?m-????-  ?D?F???X?Y????N"O)G???C??e???U?? yN???z12??=@0~???T??*??5????X??p??`[+????`?\?F$?;?J?~(?|A????Zhh?"^??~???4gT?o?b??4?J?????>?????G{n-?%???8)jk??#??B?j???R?6???f?t_?.?Q?O~T??;?_??T?0??c?????S
            D/OkHttp: ?e1?n??"???l?G+.?????+?@?2\   ??I?9?U?B~??y|Z?#??K1?=?H?~??T|??mE h5q????&??l?????G?\?U=M?[@M???)???d??   ???rl???<i???
            D/OkHttp: 5m?r_!?4P[??(??c???T??KmQ?A?|/3?v?????????? lv?C5?~)'1?*?M?W??}?}?j??fSI???w?????jfL?Q?TTmI?D?????V?\@?YA???e\?X??9*?M?*?-n???ET??}$?W?ZL6XP??];9?>T??    y?L q???????\??????>K[??!?#??t???S???Gl??
            D/OkHttp: w?SYq??&mJ?*"}8D?PY?Gi?=K?n??ZZ???2q_}????*???{qG!?4?.?l&??2A?P??|?@OL?&???u?h?{-6k^BXa??n2l?Q_?u?hM??(?Kt??!g?d?f???V??HF???B0??p?pU)jr??|?UA?K?9B?=?\7???U?=??A????yoLw????5??1]^??)???v???S?R  ?Db????????7????m;??6sa??mV????l
            D/OkHttp: ??A?E??O??wR^??Jh?q???F?J?b?#???R?[????T?vB??~????M
            D/OkHttp: ?v?B?4I?E?42w???H%?i??J?$eR
            D/OkHttp: jrz??W@???i?(??B7?d?}???G+?   U??r???K????E??u??"Z?~???p???*a?'?"??x?3?Kd{??_?@f???????F?)??[?qq?kq?f?m"4???"?i??U?@??gX?h&t??[?I0w???j?Z?Y??
            D/OkHttp: Jp????}???1?s-5???jU%?3?????+lD,?`a}?->H?1?<???@??????(<?]H????Te ?uH????
    D/OkHttp: ??m>?Hcs?h???[&??m?T?@N????m??zg???N???*  ?*M?Wa? wJ??????V???G?kp?F~<?~??\P?????R??????d?1?a??^??Fn}?-??_5??H????P^??*?U?X6??d_?!?'??]?f??   r3?v?W?8???¨?n?}?4NL?P??6?a!?Q?Z?:]f?R+?+?r???Z^??????s1? &$?   C?$?g??@??~?%u??Z?U?#?z?|?b>a?mam?I????$q?f]ox???jI?i?c ??E`6?/m+?k?y?$m????T?_O??????S??{???q????p!nN????=??H??P???@???X0(????1?H???   ?r??????|??:??ZF?a?A?J[O?Z>??+?^'?5?ER?*?{$1?:???f*???c@??  p%5?+???]r;??mG
    D/OkHttp: 5\??k-??'???<?\??.$?v???
    D/OkHttp: ???xB????]$??$u???&J%3E$q?q?5?T8?h?*?qd??`~??LN?{g?aL???O?=????????]V??NE??u??dX?*???GF?I}5??3?un[?m?[?P*A?Tx?/XF?Q????E2???  ??fa?Zn?>O??Î)C??y?|???u????8?{???^?9??P_??)?0??+?w)??#?H<G$I??X??;?|g)z??q????)k?9+?Wn1?%?|Oj<68Z????&?b?  ??]^pW|?p?????o???Z?M6????t??7+????2?z?01z?]V?6 +??J?Akk??u5?iq?~?O??c4GH??
    D/OkHttp: ??{e[?m?m>?P??$??+J?E????h?/?{??s]?Cz]Sn??]F#
    D/OkHttp: ??y??U?1??kvp?e??Z?@???&R[    ???E453??????}$?????8?6?????????"?,?(????X*??_qE??H??"??Kw?fk???VSF?=?????[TW?R&??LRw?? ??}EU?[i??(??C????f??????????)?4??y???V'~;.??y?iu?Y3??o9?6?N?5&C???8E???.??-???????:????^|??`??u?W???rI?m?Yo?^1U&GA?`i+%?h??b?$???b\]*?M????Mw?????P?L??<J?2?R.???+,??b????)~A?n??x=?zm?<#?TK?.?Z;\????'??u??8N???-???R>?9??R??9??q?67
    D/OkHttp: ???   ??4????t??/v2?)? ?t??j??>????????6m?}5:?????#%lk?d;?P??X?????I?A?NN?H"P`???95r:?Zu???????j9?:??0?*(??:?dJ=R@'????L?{??
            D/OkHttp: ?-?????h|??t?X??:?????z?nw?p?$!D_?G?q??u??:??????O?w?^m>??(&?0$?sc?G?qWkFC?e?Y??j?????v???j???(r  ??; ?A?????Mw???[??~_?F?FXN<Ef[&??N????4???D??g?Z>uP??6?f?&??C?soSAl?d?T?@3{?tH????H??o?#??nu?_?_G{?=K?s?iU?Tz??@wy'??O?%y4?V??2YV??T;????baW?l???:R??b?9???]?~?
            D/OkHttp: A1.?????qj?TB?S??;????w??v?I+??Bw??T3Vf%2/?]?????*?d]?5z??]??*?\@(I?1)?m?-?Y?O??
            D/OkHttp: ?-??f??pw?h?)?=?? ???}?u??H?(J??u?g?!?????H{  ?-?:?i<???à.g??m???zy?}?V?Q??`?a???{?w6y??I?1??_?g?-?????{???%=^?4M?-?F!???????IP?J????7U???3i??t?@?Z?s?O;-??F]&?q?E??f???? ??T?[[3??<V????A$shq???j????_|??F??A??I9?F??@?Xi@?U=??#,??u?? ??
    D/OkHttp: ??[E#?h????q~?Pf?n???HK(?h??O?=???????(?&?/???Gi????>?BC?????S???b?l???R:??VAH?9?<?$?]#???y???H%?q?m?BQ????v?Ub???k?j????n???????????B?????:B??N?y????j???l:o??P??U???    I??;o??-??qLY?/???r?X?DEqOV?Nu??m???sR?AN   ?K??!???>?',?z1NR?2y???aq.K?-?=?>a5?D??y???T??w?%nA??;H0?`p?]?1?????q?ho??QXZ?
            D/OkHttp: ?w+?#???4???C?|??]?)?L????%?C?s<Y?1P?cq? ????X?n?S??|?[,]??9???????=H???&?f?$????,?h?F ?/?2?u???h{p???9?'[iTv??=??w???6}7JR?D?,?p5??UhR?s?t???_[????Y??,?iZe?>)?AH???Ln?B?f?K??v5??B??I?p,?D??b<$?(+???5B?;%?F-y?I?UXL??B????
        D/OkHttp: '>??(???*?@X??{?»??H???B??Z?]J+??-??CFFD"??Kmb?aMv
        D/OkHttp: ?o???,t5????? w??c[?;'
        D/OkHttp: KS ?aA;?1<?<???e??Wh?c???KH>1?{\M???sz???5?+?{fos?I???>?~[?????,j??????W?};?[H?-'??*??w??c?té????V h7?m???J?-?*-Ak?c5?}??o6a??m?N,?ucF"??xn??zI^yq?BL?????g????4???P??"?.181?z?0???|'M??]???????wbR?u??m?&? ?&????=K??#,B4?\$???I???H?G???8????3?$??-M?C??3?????\;?w??Kf??m??
            D/OkHttp: ?Fg?Qbj???s?a???G??u?.???
            D/OkHttp: !?w?E?Y?8?¿]?Q'??G2?h????z?]?o?q?K?X??hY?r?^?C?K}~M?{?&g^?An?9c{pa?????<???;??n??5r?0 ^?rb?cB<`Gw??Kr???>g9?!
    D/OkHttp: #-5??q??h?*??ui?c??T?+?V?PU?????LF?   ?=??4}??c>?]??Y?)%???MX.??y?[J??lw??!?fG?nW??O?!??U%????W?8o;? ??0v?z?j'
    D/OkHttp: +b9Erq?z!G??:i?3?Y??B?A????{?I?Hd? ?~?w[r0)?s??4?I?yN?ka???e7?5????}/?xq?c]P0u?H?7?????U+5P??BX??f?%?E??Jq?3-x?u??8C??A???p?5?>??eu}?q?{Q??vH<??z??a¹??B  @M??kN? ?+X?e???2F
    D/OkHttp: k?8B8???vN????å???K?l??tX?N?Zy ?m??U?M????-??T??-????c?7??,???[?s?|6!???~?hY??!?X??I!??4Zh?   ?}Ka?C$%!3B?z-?r??Id?xz??   B?Jl-t"E?I?N???? ???&]
    D/OkHttp: u3&???%?f?!??CK?cJi!P?u?YKF?g? ????s?&?Ip76??,??
    D/OkHttp: ?)j?????9r???^????|?b??|?????Tq?E??Y1p????a????qu?z?9?9??h}?A??48?p???6J??????8?0%?j??.??|????;?j?l???K??Y??*?I   ??J?O??t?????@Z?Q1 @??)?t?%???p?F[
    D/OkHttp: y?]a?6%G  ?IW?+?u%?8??
    D/OkHttp: ???X?ck*v+?//?D??gw6?v????_????%??????R?+???`qmJ?3?n?RsQ?-#,?2?????A?XB?s?+?!????sn,m??A??b?15?sm?V
                D/OkHttp: ?????W?z?I?[???p?R???b?~4R:?N??/?T?v?U?!}??hQ??J?????z6{#n???M??  ??
            09-14 13:09:28.682 19619-19794/com.merchantproxy.merchantproxy D/OkHttp: ?????1?,??dk?v?g&??B??H?&?F??????5?U???o??Mzg?>?\?????VNs\?
            09-14 13:09:28.682 19619-19794/com.merchantproxy.merchantproxy D/OkHttp: <n? d???R??t?i??Y???rK?Q?t??????=D?8P??Z??? <?g???w???B?}??D?p?Z~?????7??!m=q?hIv??&7?_?!??O??Cs??&7vVV?QW???!!?}r?6IX????b?(?B?+J????y?'!?E?*???$??]-?r?T???G???p??u??7;)??h.??G???#<???1?????+??????O?`m?F??k"Q?????|??Q?"??A?e?c??z.?sh?3=???hK??##????3f???cT??g??V?0{???{??\?j\ ?8gW?O6??J'K??~ %?n?zPN??U|????[???????????R??????????D1?????S???Xa????!rg?&F?'=?G??e?????z?????g??Ty??QU9S??l+?;H ?a[???z???S??u??N???7i??8??????w_?m1????
    D/OkHttp: ??D???ai??????|.???}??I?x???H???}??`???????E????????d????1    ?6????F?ol???8HZ7?????G??????K?U?S?)a?????,!??u_?M?q?]??}???Y8M
    D/OkHttp: ?9?^?F???r?G?G??t?v????>A?/?y???%?5???c4? ?z"`???M?1o??9=????2?? ?^D????N?c??????l???%4"?U?Al?<?Z??Xa?HpM?%????? h?+?=???V??}????A
    D/OkHttp: b??!???????[?j?V?2???c<?k?$??>K??@ ??|??J?},?C?J?/??m5k???9??c??ffY'???9?9?m??\L??h0t[??S}?/?V??????}?w?VK2??????
    D/OkHttp: r?WE???)?g?|??-1=?YiU(:???(f??{T*We?]z?b??}?L?8HV??Ec??m?m?R??'Y?????????-?K?S??^Vu?~?I   V??C????T?9?1M?}w??XH ?&m8#?3H??}???<EK???YK?h?Wy??$?y?0??.???g]%C?n??=???tUf0?N G?`?w?????]m?z?8)?e?H;??N??????C?c"?Z?BGH??4?&!???*>Gg???m??\? *o??=?n??$]?????X???*?D&??k?o??UK?|$??`???r<???(1Ô@?t1
    D/OkHttp: [m/???m?Z?? rk?&e?????C?-?\.??r?$?T???m?q?$K?B??
    D/OkHttp: ??|9????????k{????????K??}z?~W?|??mJ ?d??j?????M????S??;wZ?Fj?.???N?O?J????:??}}????>??@#u?qo??%Q?b?????ux?\???w??)?1?d???)??(??7??cD??j9/?8:?>??I?qd??r]'?B=%3?i^Vrf??L???
    D/OkHttp: n??~f??W??#?u??s???|?????5=?????ua??s??*AZ??[4??c?!?)??~?-??|???~?}*,??*?C???I?)U?    ?????8)????L??;???U??~?u?F???5?GL,?V?I??DE I?;?%#X__5x??4jd?X??yE????>3?
    D/OkHttp: n??'A?m?P?0?#?-??K?+4???6bF1*??l??#?%??WC@T?J???4??(/Z???*??^?B??????Nd??YT???????UC?B?8?X???}???????\??#G?+(/g81?]7L???qk???'*?z?+)a??+?E?,o?    ?~??E????
    D/OkHttp: ;?{?I???&?/?p&??M?N??z??>?rl?6T-4ta9?<M??46?????s??'-?????\/??yS???TA_?|~^~??,-o?Jy??lBT??Ec?2\l??uw?)]`?6-f?,?K???j*nrf3???Z???k????@??UC@ h?aR?@CvA???8?dH????1?ky????$%????[??@?????mD????N?c,?FO???$?=4:??L!??????NP?G5????L???5???!????p??|V?2??#?%? ?V??m.?`???>og??*?!c??O??]ZU??????*ILq?o?Y??=??!O?-?!?y?0}v?r????}UV&~?#    ?MQ????????X?|??ABP?b?z?6}??<'?W?w8?y?{)8c
    D/OkHttp: ?\?"??#H??m??"??[????\?[0%????@[??-?E??8???|??????ma?*?|?{-??E+2?0!???;fQD?????@>????P??y??YKu?
            D/OkHttp: Lm??X?????m?T????N????C?%?)Q? ,???l.???k??]r?<?O??)¢?y??Q?S?1??B?Z?[?@?/hp?ty??FPh.'uCF?+?@P??I?v?:??b
    D/OkHttp: b??:
    D/OkHttp: ?.t??
    D/OkHttp: ?~4?.?WiDq=mN?(k??*v????<]??@???K???,??$???i?p
    D/OkHttp: ?+?KT??   ie!?V?s,"u??Rs??=?'}?4t5?#?v?*?B ?l/bk?@cS?R??????pk?241?XP?8????&??p??C??%r? ??6K??????]ro?D??PP??#??m????????-T??8??%?d#5??P?X?Mq??n????????/cG!??cb???Zs???p???f_?yj??m?#??}?/0??=???v_?D ??<?{?\d9?2rSÀ??-?F???,n?q???????-?z?????g!?????|??;??@x<?r?h?Q?5%c-???>??M?????_+???e?t?y-c?*?QX? <?1?I?? ???#?1?i?+c???c???v?6?|??f? ;$K???$l3?`?qk?o&-???"h._"?F ?[????r??~D?????IG??@??J?o.'7?%J?:$>??D???u4&??<???r???L??1??k?h?L?e?? .???1vD?C??9?????1,???=U?8??L??(EO?d0?Z???:?cxx??|y??a.???`0&??`0?0?    ??`0L ??`0?0?   ??`0L ??`a0??`0L ??`a0??`0?@???`0??`0?@???`0&??`0?0???`0&??`0?0?    ??`0L ??`0?0?   ??`0L ??`a0??`0L ??`a0??`0?@???`0??`0?@???`0&??`0?@???`0&??`0?0?    ??`0&??`0?0?    ??`0L ??`a0?    ??`0??`???Q?v??????????IEND?B`?
            D/OkHttp: --965ee1a1-6194-4fc7-93ff-d444218f05bc--
    D/OkHttp: --> END PUT (15878-byte body)
    D/OkHttp: <-- 200 OK http://test.dev.com/api/v1/main/users/user-details (214ms)
    D/OkHttp: Date: Thu, 14 Sep 2017 10:10:11 GMT
    D/OkHttp: Server: Apache/2.4.7 (Ubuntu)
    D/OkHttp: Vary: Authorization
    D/OkHttp: Access-Control-Allow-Origin: *
    D/OkHttp: Access-Control-Allow-Headers: Origin, Content-Type
    D/OkHttp: Cache-Control: no-cache
    D/OkHttp: Set-Cookie: laravel_session=eyJpdiI6IlwvVzhJT3BTajM5czQ5cGowU05aZ21RPT0iLCJ2YWx1ZSI6IjlvUmN3V1ZxZE9OaWJJcUZoam9xazkxRWRTMjgrRnNcL3E0UXpWbjhTbjhTMU1yZmE4T01vRjhzS3hTKzJQQ2kxUVFXQTh0SnhmakdyVlhKcHo2M253UT09IiwibWFjIjoiOGYwMWVjOTk5Y2NkYWViMmU5YWM3MDllN2IzMjc2N2JhZDE3MTM2ZmQxZGE1M2U3MmViZTZiMTM4MjFhZjE3MSJ9; expires=Thu, 14-Sep-2017 12:10:11 GMT; Max-Age=7200; path=/; HttpOnly
    D/OkHttp: Content-Length: 49
    D/OkHttp: Keep-Alive: timeout=5, max=100
    D/OkHttp: Connection: Keep-Alive
    D/OkHttp: Content-Type: application/json
    D/OkHttp: {"success":true,"user_details":null,"image":null}
    D/OkHttp: <-- END HTTP (49-byte body)`

In laravel:

`public function putUserDetails(){
        $user_details = \Input::get('user_details');

        return response()->json(['success' => true, 'user_details' => $user_details, "image" => \Input::get('profile_picture')]);

    }`

Any idea about what am I doing wrong? Thank you all for your time!

kaimou1357 commented 7 years ago

Correct me if I'm wrong, but doesn't the Content-Type have to be "multipart/form-data" if you want to work with files? Shouldn't we look into the issue with the header you currently have now? (application/json)

Heri88 commented 7 years ago

I have encountered a similar problem when using laravel. Any solution or hack to this?

JakeWharton commented 7 years ago

What behavior of Retrofit is problematic here? The request body looks fine.