Forum Discussion

subra7978's avatar
subra7978
Occasional Contributor
8 years ago

Put Object to AWS S3 using multipart/form-data

I am trying to upload an image file to AWS S3 using HTTP PUT in a REST project. I have tried the following:

(1) Use a multipart attachment did not work because SoapUI inserted attachment headers which AWS inserted as part of the file. I read there was an option to disable multiparts, but could not find it. 

(2) I used the following Groovy script to read the image into a single-byte string inserted the result of teh script into the payload of the request. This alsmost worked. But the iso-8859-1 encoding changed some bytes and corrupted the image. 

import org.apache.commons.io.FileUtils;
def filename = "path/to/file/name";
File file = new File(filename);
def str = new String(file.readBytes());
return str;

 

Please help. 

4 Replies

  • kondasamy's avatar
    kondasamy
    Regular Contributor

    The safest way to deal with multipart request is to use the attachment option in SoapUI. We can help with appropriate solution if you share a sample request the AWS is expecting.

     

    Thanks,

    Kondasamy

    • subra7978's avatar
      subra7978
      Occasional Contributor

      Thanks for the reply. In the screenshot above, one can see the raw multipart request from Soapui that has inserted a header for the attachment. I then downloaded the uploaded file from AWS S3 and a file "diff" with the original image shows the header has been included in the file content. So I gather AWS does not expect this multipart header. It counts everything after the message header as payload.