Skip to main content
Notice removed Canonical answer required by CommunityBot
Bounty Ended with no winning answer by CommunityBot
deleted 766 characters in body
Source Link

SOLUTION!

    InputStream in = new FileInputStream(file);
    byte[] buf;
    buf = new byte[in.available()];
    while (in.read(buf) != -1) {

    }
    RequestBody requestBody = RequestBody
            .create(MediaType.parse("application/octet-stream"), buf);

and send the created requestBody as the body of the POST. In my case, I am using RxJava, so the ApiService call looks like:

@POST(ApiUrls.Endpoint.UPLOAD_IMAGE_ATTACHMENT)
Observable<Void> uploadImageAttachment(
        @Header(ApiUrls.Param.X_REQUEST_DIGEST) String digestValue,
        @Path(ApiUrls.Param.RESULT_ID) int resultId,
        @Path(ApiUrls.Param.FILE_NAME) String fileName,
        @Body RequestBody photo);

SOLUTION!

    InputStream in = new FileInputStream(file);
    byte[] buf;
    buf = new byte[in.available()];
    while (in.read(buf) != -1) {

    }
    RequestBody requestBody = RequestBody
            .create(MediaType.parse("application/octet-stream"), buf);

and send the created requestBody as the body of the POST. In my case, I am using RxJava, so the ApiService call looks like:

@POST(ApiUrls.Endpoint.UPLOAD_IMAGE_ATTACHMENT)
Observable<Void> uploadImageAttachment(
        @Header(ApiUrls.Param.X_REQUEST_DIGEST) String digestValue,
        @Path(ApiUrls.Param.RESULT_ID) int resultId,
        @Path(ApiUrls.Param.FILE_NAME) String fileName,
        @Body RequestBody photo);
Tweeted twitter.com/StackSharePoint/status/947353188868476928
added 397 characters in body
Source Link

and send the created requestBody as the body of the POST. In my case, I am using RxJava, so the ApiService call looks like:

@POST(ApiUrls.Endpoint.UPLOAD_IMAGE_ATTACHMENT)
Observable<Void> uploadImageAttachment(
        @Header(ApiUrls.Param.X_REQUEST_DIGEST) String digestValue,
        @Path(ApiUrls.Param.RESULT_ID) int resultId,
        @Path(ApiUrls.Param.FILE_NAME) String fileName,
        @Body RequestBody photo);

and send the created requestBody as the body of the POST.

and send the created requestBody as the body of the POST. In my case, I am using RxJava, so the ApiService call looks like:

@POST(ApiUrls.Endpoint.UPLOAD_IMAGE_ATTACHMENT)
Observable<Void> uploadImageAttachment(
        @Header(ApiUrls.Param.X_REQUEST_DIGEST) String digestValue,
        @Path(ApiUrls.Param.RESULT_ID) int resultId,
        @Path(ApiUrls.Param.FILE_NAME) String fileName,
        @Body RequestBody photo);
added 369 characters in body
Source Link

SOLUTION!

    InputStream in = new FileInputStream(file);
    byte[] buf;
    buf = new byte[in.available()];
    while (in.read(buf) != -1) {

    }
    RequestBody requestBody = RequestBody
            .create(MediaType.parse("application/octet-stream"), buf);

and send the created requestBody as the body of the POST.

SOLUTION!

    InputStream in = new FileInputStream(file);
    byte[] buf;
    buf = new byte[in.available()];
    while (in.read(buf) != -1) {

    }
    RequestBody requestBody = RequestBody
            .create(MediaType.parse("application/octet-stream"), buf);

and send the created requestBody as the body of the POST.

added 633 characters in body
Source Link
Loading
Notice added Canonical answer required by Arsalan Adam Khatri
Bounty Started worth 100 reputation by Arsalan Adam Khatri
added 21459 characters in body
Source Link
Loading
Source Link
Loading