Ask a Question

SOAPUI - UPLOADING A FILE

Silviu_Asandei
New Contributor

SOAPUI - UPLOADING A FILE

Hello,

I want to use SOAPUI, in order to upload a file, and then to receive that file back to me, modified or not. How can I do that?
19 REPLIES 19
omatzura
Super Contributor

Hi!

Quick walkthrough:

1) Create a new Project
2) Create a TestSuite in the Project
3) Create a TestCase in the TestSuite
4) Add an HTTP TestRequest Step to the TestCase
-> Set the endpoint to the URL you want to upload to
-> Set the method to POST (or PUT)
5) In the Request Editor add the File you want to upload to the Attachments tab
6) Set the Media-Type of the POST Body to the same as the Content-Type of the attached File
7) Send the request!

Hope I got that right πŸ™‚

/Ole
eviware.com
aaron_ehrensber
Contributor

Is there anyway to add files dynamically - ie - read in 20 files out of a datasource and toss them in 20 concurrent threads for 20 requests?  Using the attachment button wouldn't allow this would it? 

aaron
omatzura
Super Contributor

Hi!

would you store the files themselves in the DataSource or just the filenames?

regards,

/Ole
eviware.com
aaron_ehrensber
Contributor

Ideally, just the filenames.

So, store the filenames in a datasource and retrieve the name.  I can do this....

But how do I build the actual HTTP Request with the changing filename representing the file I want to attach?  That's my core question.

aaron
omatzura
Super Contributor

Hi,

you can either create a groovy script that does the actual attaching of the file or you can use property-expansion in the filename of the attachment and set it to not be cached.

Hope this helps!

regards,

/Ole
eviware.com
aaron_ehrensber
Contributor

I'd like to use a groovy script to attach the file, but this is probably a question I should have asked long ago....

How do I know the syntax to use?  Is there a Groovy API somewhere?  A soapUI api somewhere?  I feel a lot of my questions might have been avoided if I truly knew where to look for an api-type answer.

aaron
omatzura
Super Contributor

Hi!

you can do something like the following:

// get request
def request = testRunner.testCase.getTestStepByName( "Request" ).testRequest

// clear existing attachments
for( a in request.attachments ) {
request.removeAttachment( a )
}

// get file to attach
def file = new File( "file to attach" )
if ( file == null) {
log.info "bad filename"
}
else
{
// attach and set properties
def attachment = request.attachFile( file, true )
attachment.contentType = "application/octet-stream"
attachment.setPart( "Message" )
}


This should get you started..

regards,

/Ole
eviware.com
Chris_M
New Contributor

I also want to upload a file, but in this case it is an audio file that gets submitted to the web service. The problem I am having is that it is naturally encoded when uploaded to a web service via a windows form, but not automatically encoded when submitted via SOAP UI.

When I wrote the client in visual studio I did not do anything other than add a box to browse to the file. I'm not sure how or why the windows form handles this automatically.

Thank you,
Chris
omatzura
Super Contributor

Hi Chris,

Hmm.. How do you want the file to be encoded?

regards!

/Ole
eviware.com
cancel
Showing results forΒ 
Search instead forΒ 
Did you mean:Β