I am building a document management service with a RESTful API.

@Path("fileUpload")
public class FileUploadService
{
  @PUT
  @Produces(MediaType.APPLICATION_JSON)
  @Consumes(MediaType.MULTIPART_FORM_DATA)
  public Response uploadFile(@FormDataParam("file") InputStream fileStream,
          @FormDataParam("file") FormDataContentDisposition fileDetail) throws IOException
  {
   .... 
  }
}

It seems to work as expected if I use a third party client such as Postman. However, when using the REST activity of ivy I am unable to call this service. I always get errors stating the the header X-Requested-By is missing. Whats the issue? How can I send files using a REST Client Call activity?

asked 18.04 at 04:05

SupportIvyTeam's gravatar image

SupportIvyTeam ♦♦
1.2k83107116
accept rate: 76%

edited 18.04 at 04:27


Hi. The problem with X-Requested-By is that it shows up a lot even if it's not the problem. This issue was fixed in XIVY-3097. So if you are sending a modyfing request like PUT or POST and you are sure that you set X-Requested-By Header then it's other issue. What your problem probably is, is that you need to set MediaType boundary like

MediaType contentType = MediaType.MULTIPART_FORM_DATA_TYPE;
contentType = Boundary.addBoundary(contentType);

and use it in your entity as content-type. And it will not work if you use MediaType.MULTIPART_FORM_DATA_TYPE instead of contentType

Example:

MediaType contentType = MediaType.MULTIPART_FORM_DATA_TYPE;
contentType = Boundary.addBoundary(contentType);

Response apacheConnectorResponse = client
        .target(uri).request()
        .header("X-Requested-By", "ivy")
        .put(Entity.entity(createMultipart(realPdf), contentType));

You are able to see the full example in ConnectivityDemos (7.3 and newer) > rest > FileUpload

link

answered 18.04 at 04:19

Jacek%20Lajdecki's gravatar image

Jacek Lajdecki
66119
accept rate: 100%

edited 06.09 at 02:36

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×25
×16
×7

Asked: 18.04 at 04:05

Seen: 181 times

Last updated: 06.09 at 02:36