Forum Discussion

danielatsi's avatar
New Contributor
7 years ago

Problem with content-type when attaching file to SoapUI rest request

Problem with content-type when attaching file to SoapUI rest request 


can somebody help me with the following issue that I have when trying to attach a file to Rest Post request?


I want to attach a .png file to my rest request in SoapUI free version, the problem is that SoapUI puts in the Raw of the request Content-Type: image/x-png instead of image/png


It looks like this in the Raw tab:


Content-Type: image/x-png
Content-Transfer-Encoding: binary
Content-Disposition: form-data; name="energy.png"; filename="energy.png"


and my server is expecting content-type image/png, for which reason I am getting error: errorMessage": "File must be in one of the following formats: [image/png]


I have a QUERY parameter in my request with value file:filename, where filename is the complete path to the file on the local hard drive (that was the way to avoid appending the file name together with file type in the Content-type in Raw)


Thank you!

3 Replies

  • JHunt's avatar
    Community Hero

    It looks like a bug, since there shouldn't be that name=help.png there in the Content-Type. I get the same thing on SoapUI 5.4.0.


    You are working around it by using Post QueryString and reading a file for the value of one of the parameters. Unfortunately, this is hard coded to use image/x-png and not image/png. The former is used for legacy support, even though image/png is standardised now.



    public class ContentTypeHandler {
        static {
            suffixToContentType = new HashMap<String, String>();
            suffixToContentType.put("gif", "image/gif");
            suffixToContentType.put("xbm", "image/x-xbitmap");
            suffixToContentType.put("xpm", "image/x-xpixmap");
            suffixToContentType.put("png", "image/x-png");
            suffixToContentType.put("ief", "image/ief");
            suffixToContentType.put("jpeg", "image/jpeg");
            suffixToContentType.put("jpg", "image/jpeg");
            suffixToContentType.put("tiff tif", "image/tiff");
            suffixToContentType.put("tif", "image/tiff");
            suffixToContentType.put("rgb", "image/rgb");
            // suffixToContentType.put("", "image/x-rgb");
            suffixToContentType.put("g3f ", "image/g3fax");
            suffixToContentType.put("xwd ", "image/x-xwindowdump");
            suffixToContentType.put("pict", "image/x-pict");
            suffixToContentType.put("ppm", "image/x-portable-pixmap");
            suffixToContentType.put("pgm", "image/x-portable-graymap");
            suffixToContentType.put("pbm", "image/x-portable-bitmap");
            suffixToContentType.put("pnm", "image/x-portable-anymap");
            suffixToContentType.put("bmp", "image/x-ms-bmp");
            suffixToContentType.put("ras", "image/x-cmu-raster");
            suffixToContentType.put("pcd", "image/x-photo-cd");
            suffixToContentType.put("cgm", "image/cgm");
            // suffixToContentType.put("", "image/naplps");
            suffixToContentType.put("mil", "image/x-cals");
            suffixToContentType.put("cal", "image/x-cals");
            suffixToContentType.put("fif", "image/fif");
            suffixToContentType.put("dsf", "image/x-mgx-dsf");
            suffixToContentType.put("cmx", "image/x-cmx");
            suffixToContentType.put("wi", "image/wavelet");
            suffixToContentType.put("dwg", "image/vnd.dwg");
            // suffixToContentType.put("", "image/x-dwg");
            suffixToContentType.put("dxf", "image/vnd.dxf");
            // suffixToContentType.put("", "image/x-dxf");
            suffixToContentType.put("svf", "image/vnd.svf");

    I don't know how you'd do something about the bug with adding name to the content-type.


    If you know how to build SoapUI from the source code, you could modify the above HashMap in src\main\java\com\eviware\soapui\support\editor\inspectors\attachments\, and continue using your workaround.


  • JHunt's avatar
    Community Hero

    On the attachments tab, there is a column for Content-Type and you can just edit it there by double clicking. I was able to set Content-Type = image/png.


    Unless I'm missing some requirement  or complication from you?


    Content-Type: image/png; name=SoapUI-Spashscreen.png
    Content-Transfer-Encoding: binary
    Content-Disposition: form-data; name="SoapUI-Spashscreen.png"; filename="SoapUI-Spashscreen.png"



    • danielatsi's avatar
      New Contributor

      Hi, thank you for your reply.


      I did edit the Content-type column in the attachment tab earlier but I could'n succeed sending the file.


      Can you please have a look at the 2 attached files below - 1 with my request and the other with the raw of it and tell me where am I missing something?


      Thank you!