Forum Discussion

danello's avatar
10 years ago

Duplicate file attachments in SoapUI

When using file: to bind an attachment to a QUERY parameter on a REST POST method, the attachment is sent twice: Once as the intended attachment type, and once as application/octet-stream. This only happens when the attachment is some sort of text data. If I specify a file that contains binary data, only 1 copy is sent.

I've duplicated the behavior in both SoapUI 4.6.4 and 5.0.0.
[hr:172kwx79][/hr:172kwx79]
Request Setup
Method: POST
Endpoint: http://localhost:8080
Resource: /api/image-converter/svg-to-png
Media Type: multipart/form-data
Post QueryString: true

Parameters
  • Name=data
    Value=file:sample.svg
    Style=QUERY
    Level=METHOD


Attachments
  • Name=sample.svg
    Content type=image/svg+xml
    Size=321
    Part=
    Type=UNKNOWN
    contentID=sample.svg
    Cached=true


Auth
Authentication Type=Preemptive
Username=sample
Password=*******
[hr:172kwx79][/hr:172kwx79]
And here is the raw request that is sent

POST http://localhost:8080/api/image-converter/svg-to-png HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: multipart/form-data; boundary="----=_Part_3_1104180060.0000000000000"
MIME-Version: 1.0
Authorization: Basic ZGFuZWxsb0BDUkEuTEFOOkZsQG0zbmMwbmU=
Content-Length: 6895
Host: localhost:8080
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)

------=_Part_3_1104180060.0000000000000
Content-Type: application/octet-stream
Content-Transfer-Encoding: binary
Content-Disposition: form-data; name="data"; filename="sample.svg"

*** XML SVG contents omitted ***

------=_Part_3_1104180060.0000000000000
Content-Type: image/svg+xml; name=sample.svg
Content-Transfer-Encoding: binary
Content-Disposition: form-data; name="sample.svg"; filename="sample.svg"

*** Same XML SVG contents duplicated here ***


Response
The response is correct given the input as we have a filter that rejects unknown content types:

HTTP/1.1 400 Bad Request
Server: Apache-Coyote/1.1
Set-Cookie: JSESSIONID=BC9DF6696D15100E541F7608CE76C819; Path=/
Content-Type: text/plain
Transfer-Encoding: chunked
Content-Encoding: gzip
Vary: Accept-Encoding
Date: Tue, 24 Jun 2014 15:56:37 GMT
Connection: close

Illegal media type 'application/octet-stream': only image/svg+xml is accepted.


The sample file being attached is simply the sample SVG image from wikipedia obtained from here:
https://upload.wikimedia.org/wikipedia/commons/6/6b/Bitmap_VS_SVG.svg
[hr:172kwx79][/hr:172kwx79]
The desired behavior would be to have just a single form-data part be sent that looks like this:

POST http://localhost:8080/api/image-converter/svg-to-png HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: multipart/form-data; boundary="----=_Part_3_1104180060.0000000000000"
MIME-Version: 1.0
Authorization: Basic ZGFuZWxsb0BDUkEuTEFOOkZsQG0zbmMwbmU=
Content-Length: 6895
Host: localhost:8080
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)

------=_Part_3_1104180060.0000000000000
Content-Type: image/svg+xml
Content-Transfer-Encoding: binary
Content-Disposition: form-data; name="data"; filename="sample.svg"

*** XML SVG contents omitted ***

1 Reply

  • Hi,

    Change the Content-Type in the attachments tab to image/svg+xml. For the type of file by default it is set to application/octect+stream. The request will still be sent in two parts but the first part will be text/plain for the Content-Type and second will be image/svg+xml with the contents of the file.

    ------=_Part_3_1270470141.1404155087471
    Content-Type: text/plain; charset=us-ascii
    Content-Transfer-Encoding: 7bit
    Content-Disposition: form-data; name="part"

    image.svg
    ------=_Part_3_1270470141.1404155087471
    Content-Type: image/svg+xml; name=Bitmap_VS_SVG.svg
    Content-Transfer-Encoding: binary
    Content-Disposition: form-data; name="Bitmap_VS_SVG.svg"; filename="Bitmap_VS_SVG.svg"

    <contents of the file>