2

I let my user select a picture in their gallery, save its Uri, set a title and description and wish to upload it anonymously using Imgur's API, with this endpoint using Retrofit 2.

So far, this is what I am doing with no success:

In my ImgurAPI interface:

@Multipart
@POST("image")
Call<BrowseData>  postImage(
        @Header("Authorization") String auth,
        @Part MultipartBody.Part file,
        @Query("image") String image,
        @Query("album") String albumId,
        @Query("type") String type,
        @Query("title") String title,
        @Query("description") String description
);

In my API handler:

public void uploadImage(Uri fileUri, String image, String album, String type,
                        String title, String description) {
    // create upload service client (retrofit builder and such)
    ImgurAPI service =
            ServiceGenerator.createService(ImgurAPI.class);

    File file = FileUtils.getFile(caller.getActivity(), fileUri);

    // create RequestBody instance from file
    RequestBody requestFile =
            RequestBody.create(
                    MediaType.parse(caller.getActivity().getContentResolver().getType(fileUri)),
                    file
            );

    // MultipartBody.Part is used to send also the actual file name
    MultipartBody.Part body =
            MultipartBody.Part.createFormData("picture", file.getName(), requestFile);

    // finally, execute the request
    Call<BrowseData> call = service.postImage(clientId, body, image, album, type, title, description);
    call.enqueue(new Callback<BrowseData>() {
        @Override
        public void onResponse(Call<BrowseData> call,
                               Response<BrowseData> response) {
            Log.v("Upload", "success");
        }

        @Override
        public void onFailure(Call<BrowseData> call, Throwable t) {
            Log.e("Upload error:", t.getMessage());
        }
    });
}

That is called like such on a simple FAB click:

controller = new ImgurAPIHandler(this);
controller.uploadImage(chosenUri, encodedImage, "AlbumName", "base64", title, desc);

But upon executing the request, I get the following error:

Write error: ssl=0x9c531200: I/O error during system call, Broken pipe

Can somebody explain to me what I am doing wrong? (If you have sufficient information).

Christopher
  • 139
  • 3
  • 11
  • Possible duplicate of [javax.net.ssl.SSLException: Write error: ssl=0x7f70604080: I/O error during system call, Broken pipe](https://stackoverflow.com/questions/38016109/javax-net-ssl-sslexception-write-error-ssl-0x7f70604080-i-o-error-during-syst) – Thomas Jun 28 '17 at 09:22

0 Answers0