rest-assured icon indicating copy to clipboard operation
rest-assured copied to clipboard

unable to pass attachment and json together

Open Appmakers123 opened this issue 2 years ago • 2 comments

Hi, i want to make a API automation using rest assured i am trying to sent a request where we have a file upload in body also it has some json string in body too how to add both at once please help to resolve this issue

public void Uploaddoc() throws IOException { File testuploadFile = new File("file path");

	String payload ="content in jason";

   RequestSpecification response = (RequestSpecification) given().
		   	relaxedHTTPSValidation().
			baseUri("url").port(port).
			headers("Authorization", "Bearer "+getToken).
			
			body("testuploadFile,payload").
	when().
			post("/path").
	then().
	log().all();
	extract().response();

Appmakers123 avatar Apr 25 '23 16:04 Appmakers123

I checked two examples of file upload. I guess using .multipart method is the way to upload files.

https://github.com/rest-assured/rest-assured/blob/69576e40485c452be05a118a6b4271857d86fb21/examples/spring-mvc-webapp/src/test/java/io/restassured/examples/springmvc/controller/FileUploadUsingStandardRestAssuredITest.java#L40

h3xh4wk avatar May 08 '23 04:05 h3xh4wk

Thank you @h3xh4wk , issue resolved by multipart method on file and json string in body with multipart

Appmakers123 avatar May 08 '23 04:05 Appmakers123