eclipse / microprofile

Repository for important documentation - the index to the project / community
Apache License 2.0
668 stars 115 forks source link

How do you send simple byte array through POST method #192

Open manodupont opened 3 years ago

manodupont commented 3 years ago

I just want to send a byte array that would correspond to the curl method as is

curl --location --request POST 'myurl' \
--header 'Authorization: Bearer {{TOKEN}}' \
--header 'Content-Type: image/jpeg' \
--data-binary '@/Users/myfile/location.jpg'

I tried so many things ..... nothing seems to work.

The further i went is this

@POST
    @Path("{bucketName}/o")
    @Consumes("image/jpeg")
    @Produces(MediaType.APPLICATION_JSON)
    GCPUploadResponseDto upload(@HeaderParam(HttpHeaders.AUTHORIZATION) String bearerToken,
                                @HeaderParam(HttpHeaders.CONTENT_TYPE) String contentType,
                                @PathParam String bucketName,
                                @QueryParam("uploadType") String uploadType,
                                @QueryParam("name") String filename,
                                byte[] data);

A little background: Im using this to upload to GCP Storage. Good news is : I do have an entry created on GCP but with 0 bytes.

It seems like the Content-Length stays at 0.

I tried many things related to the byte array that i sent. Trying with some annotations like @RequestBody, i also tried with some OutputStream, nothings seems to fix the thing.

A lot of time it happens to return also this error Caused by: org.apache.http.ProtocolException: Content-Length header already present

And on top of that, it seems like i can't find anything on google related to Microprofile byte array.

Is this feasible in the end ?!

Thanks.

Im running on Quarkus, with this lib : microprofile-rest-client-api-1.4.1.jar

Thank you.

Emily-Jiang commented 3 years ago

@manodupont since this is related to Quarkus, I suggest you ask this on Quarkus mailinglist.

manodupont commented 3 years ago

Well, thanks for the advise.

Although, i would like to get some information around sending binary data with MicroProfile Rest client ?!

Is there any doc related to that ? I can't find anything except multiform data part, but what about simple body with data byte array.

Thanks.