0

Postman - Post Request api Details for uploading images

I am performing POST request for uploading multiple images. Below is a Postman screenshot where everything works fine and I am getting the right response. But then I need to implement the same using RestAssured Program.

Above is the snapshot of the program which I tried but then I am not getting the 500 error don`t know what is missing what wrong I am doing here.

import io.restassured.RestAssured;
import io.restassured.response.Response;
import io.restassured.specification.RequestLogSpecification;
import io.restassured.response.Response;
import io.restassured.specification.RequestSpecification;

Class UploadImages_API {

RestAssured.baseURI = "http://azrvqmobfletap2.corp.ryder.com:86";
httpRequest = RestAssured.given().log().all();

 String file1_new1 = System.getProperty("user.dir")+"\\src\\main\\resources\\ImageUpload\\1.jpg";
String file2_new2 = System.getProperty("user.dir")+"\\src\\main\\resources\\ImageUpload\\2.jpg";
String file3_new3 = System.getProperty("user.dir")+"\\src\\main\\resources\\ImageUpload\\3.jpg";

httpRequest.given()
    .formParam("Year", "2008")
    .formParam("make", "Ford")
    .formParam("model", "Cascadia")
    .formParam("angleTokens", "top,left,bottom")
    .formParam("productCode", "485274")
    .multiPart("pictureData","file1_new1")
    .multiPart("pictureData","file2_new2")
    .multiPart("pictureData","file3_new3");

    response = httpRequest.post("/UsedTrucksInventory/api/Image/UploadImage");

    System.out.println(" Response : "+response.asString());

}
James Z
  • 12,209
  • 10
  • 24
  • 44
Balaji Singh .Y
  • 683
  • 2
  • 9
  • 22

1 Answers1

0

I found answer to my question. Below is the code

import io.restassured.RestAssured;
import io.restassured.response.Response;
import io.restassured.specification.RequestLogSpecification;
import io.restassured.response.Response;
import io.restassured.specification.RequestSpecification;

Class UploadImages_API {

RestAssured.baseURI = "http://azrvqmobfletap2.corp.ryder.com:86";
httpRequest = RestAssured.given().log().all();

File file1_new1 = new File(System.getProperty("user.dir")+"//src//main//resources//ImageUpload//1.jpg");
File file2_new2 = new File(System.getProperty("user.dir")+"//src//main//resources//ImageUpload//2.jpg");
File file3_new3 = new File(System.getProperty("user.dir")+"//src//main//resources//ImageUpload//3.jpg");

  httpRequest.given()
    .formParam("Year", "2008")
    .formParam("make", "Ford")
    .formParam("model", "Cascadia")
    .formParam("angleTokens", "top,left,bottom")
    .formParam("productCode", product_Code) 
    .multiPart("pictureData", file1_new, "image/jpeg")  
    .multiPart("pictureData", file2_new, "image/jpeg")
    .multiPart("pictureData", file3_new, "image/jpeg");

response = httpRequest.post("/UsedTrucksInventory/api/Image/UploadImage");
System.out.println(" Response : "+response.asString()); }

Balaji Singh .Y
  • 683
  • 2
  • 9
  • 22