Ask a Question

Trying to download attachment in response

SOLVED
nwuser
Occasional Contributor

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..

8 REPLIES 8
PrathapR
Frequent Contributor

Hi @nwuser,

 

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.

 

Redde_0-1600985358719.png

 

nwuser
Occasional Contributor

I tried that ,it didn't work.

nwuser_0-1601044558283.png

 

nwuser
Occasional Contributor

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[0].inputStream

com.eviware.soapui.support.Tools.writeAll( outFile, ins )
ins.close()
outFile.close()

step  I am getting below error

 

java.lang.ArraylndexOutOfBoundsException: 0 error at line: 5

 

Io_error_2020-09-28_17-26-02.png

 

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.

 

 

 

PrathapR
Frequent Contributor

@nwuser 

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

 

 

nwuser
Occasional Contributor

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.

PrathapR
Frequent Contributor

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).

nwuser
Occasional Contributor

Yes, I do  see my response image(Encoded) in XML tab with encoded data. with Content type..

cancel
Showing results for 
Search instead for 
Did you mean: