Datei mit Retrofit 2 hochladen

Ich versuche das ein paar Tage zu tun, und ich habe wirklich alles getan .. So sieht die Anfrage in Postman aus:

Ich bin sicher, dass alle GET-Parameter korrekt geschrieben haben. Das Problem, wie ich eine Datei zum Hochladen schicke, nehme ich an.

            Map<String, RequestBody> map = new HashMap<>();
            File file = new File("/storage/emulated/0/ConstructSecure/d1940b05-76d1-4d98-b4b4-b04b8247c8cb.png");
            RequestBody requestBody = RequestBody.create(MediaType.parse("image/png"), file);
            String fileName = file.getName();
            map.put("attachment\"; filename=\"" + fileName + "\"", requestBody);

            //GET parameters
            Map<String, String> params = new HashMap<String, String>();
            params.put("inspectionUUID", inspectionUUID);
            params.put("noteUUID", noteUUID);
            params.put("attachmentUUID", attachmentUUID);
            params.put("noteType", noteType);
            params.put("modifiedTime", modifiedTime);

            Call<ResponseBody> call = service.upload(access_token,params,map);
            call.enqueue()....

Schnittstelle

@Multipart
    @POST("api/MediaFiles/AddMediaFile")
    Call<ResponseBody> upload(
            @Header("Authorization") String authorization,
            /* GET params */ @QueryMap Map<String, String> params,
            @PartMap Map<String, RequestBody> map
    );

Kann mir jemand helfen?

Antworten auf die Frage(4)

Ihre Antwort auf die Frage