cancel
Showing results for 
Search instead for 
Did you mean: 

Trying to download attachment in response

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

1 ACCEPTED SOLUTION

Accepted Solutions
Contributor

Re: Trying to download attachment in response

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

View solution in original post

8 REPLIES 8
Highlighted
Contributor

Re: Trying to download attachment in response

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

 

Highlighted
Occasional Contributor

Re: Trying to download attachment in response

I tried that ,it didn't work.

nwuser_0-1601044558283.png

 

Highlighted
Contributor

Re: Trying to download attachment in response

Highlighted
Occasional Contributor

Re: Trying to download attachment in response

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.

 

 

 

Highlighted
Contributor

Re: Trying to download attachment in response

@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

 

 

Highlighted
Occasional Contributor

Re: Trying to download attachment in response

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.

Contributor

Re: Trying to download attachment in response

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

View solution in original post

Highlighted
Occasional Contributor

Re: Trying to download attachment in response

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

New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors