Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7839841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T15:33:59+00:00 2026-06-02T15:33:59+00:00

I want to upload a JPG file and a JSON-serialized Java object. On the

  • 0

I want to upload a JPG file and a JSON-serialized Java object. On the server I am using Apache CXF, on the client I am integration testing with rest-assured.

My server code looks like:

@POST
@Path("/document")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response storeTravelDocument(
        @Context UriInfo uriInfo, 
        @Multipart(value = "document") JsonBean bean,
        @Multipart(value = "image") InputStream pictureStream)
        throws IOException
{}

My client code looks like:

given().
    multiPart("document", new File("./data/json.txt"), "application/json").
    multiPart("image", new File("./data/image.txt"), "image/jpeg").
expect().
    statusCode(Response.Status.CREATED.getStatusCode()).
when().
    post("/document");

Everything works fine when I read the json part from the file as in the first multiPart line. However, when I want to serialize the json instance I come into problems. I tried many variants, but none worked.

I thought this variant should work: on the client

JsonBean json = new JsonBean();
json.setVal1("Value 1");
json.setVal2("Value 2");

given().
    contentType("application/json").
    formParam("document", json).
    multiPart("image", new File("./data/image.txt"), "image/jpeg").
...

and on the server

public Response storeTravelDocument(
    @Context UriInfo uriInfo, 
    @FormParam(value = "document") JsonBean bean,
    @Multipart(value = "image") InputStream pictureStream)

but no. Can anyone tell me how it should be?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T15:34:01+00:00Added an answer on June 2, 2026 at 3:34 pm

    Multipart/form-data follows the rules of multipart MIME data streams, see w3.org. This means that each part of the request forms a part in the stream. Rest-assured supports already simple fields (strings), files and streams, but not object serialization into a part. After asking on the mailing list, Johan Haleby (the author of rest-assured) suggested to add an issue. The issue is already accepted, see issue 166.

    The server will stay as it is:

    @POST
    @Path("/document")
    @Consumes(MediaType.MULTIPART_FORM_DATA)
    public Response storeTravelDocument(
            @Context UriInfo uriInfo, 
            @Multipart(value = "document") JsonBean bean,
            @Multipart(value = "image") InputStream pictureStream)
            throws IOException
    {}
    

    The client code will look like:

    given().
        multiPartObject("document", objectToSerialize, "application/json").
        multiPart("image", new File("./data/image.txt"), "image/jpeg").
    expect().
        statusCode(Response.Status.CREATED.getStatusCode()).
    when().
        post("/document");
    

    Maybe the name “multiPartObject” will change. We will see once it is implemented.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This was a question about testing file upload functionality using a local java server
i want to upload the sound file (.ogg) in server. But it should write
I want to upload and store video files to my server using PHP. Could
I want to upload a file to a ftp server programmatically (C++). If the
I want to upload images in server using ASIHTTPRequest library in my IPhone app.
I want to create a upload form. When I browse a file.Example. C:\mypicture\winter.jpg I
I am using PHP to upload a file and then I want to grab
I have a file /tmp/image.jpg that I want to upload into a BLOB field.
I want to upload and then process a file in a Ruby on Rails
I want to upload a list of users from my work's LDAP server to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.