Trying to download attachment in response
Is there a way from Ready APi to save an attachment in a response in my local directory?
Thanks for any input / ideas..
Solved! Go to Solution.
Can you please try giving local path in Dump File option of REST request properties like below.
I never a get a chance to store a attachment from response, I'm doing this to JSON response, it's just a try. If it won't work let me know, will get groovy to do that.
I tried that ,it didn't work.
While trying to put groovy script
"def testStep = testRunner.testCase.getTestStepByName( "Request_1" )
def response = testStep.testRequest.response
def outFile = new java.io.FileOutputStream( "C:\\Users\\Documents\\myfile.jpg")
def ins = response.attachments.inputStream
com.eviware.soapui.support.Tools.writeAll( outFile, ins )
step I am getting below error
java.lang.ArraylndexOutOfBoundsException: 0 error at line: 5
One more thing i want to mention my response itself is a document, and not an attachment. So basically i want to download response.
below is my response.
I'm sorry I forgot to mention In my first post, where we(In Dump file option) give local directory path to store the response, please mention file type(EX: .jpeg/pdf etc..). I tried for one REST call it did work for me.
EX Path: C:\Users\Documents\myfile.jpg
Yes , It did work , but now the problem is , it always write it in to same filename. The issue is the document which get in response has different name and filetype. So don't know how to make it dynamic.
Are you able to see anything in response, in XML tab? In my case I see my response image(Encoded) in XML tab with encoded data. with Content type. If you can see like that, we can set it the dynamic file type by writing groovy script with set property.
File name you can give something which related to REST call name and file type(Just a work around).
Yes, I do see my response image(Encoded) in XML tab with encoded data. with Content type..