cancel
Showing results for 
Search instead for 
Did you mean: 

How to download a file from ReadyAPi using groovy script

SOLVED
Highlighted
Contributor

How to download a file from ReadyAPi using groovy script

Hi 

 

Is there a way from Ready APi to download a file using groovy script, and place it in my local directory?

ie., when i hit a URL the excel file download automatically when it get downloads it must  get stored into my local directory path. and to download the file authorization is required, so how to pass the authorization?

 

Thanks in Advance.

19 REPLIES 19
Highlighted
Contributor

Hi @nmrao 

 

I have assigned the value for the custom property.

 

Thanks

 

Highlighted
Contributor

Hi @nmrao 

 

Yes i have assigned the value for the custom property and now i am getting the response as.

 

{
"message" : "You must specify only one folder in the url for POST requests."
}

Highlighted
Community Hero

Thank for trying.

But you should try it out on your own instead of just try what is mentioned.

From the error message it is clear that what you are hitting is not a file url, instead a directory.

Your question is to download a file. Isn't it?

Even you could try the your in your browser. And see.

Automation is important, but priority is to understand how things work manually and find the right way to achieve and then think of automating it. Thank you.



Regards,
Rao.
Highlighted
Contributor

Hi @nmrao 

 

Thanks for the update, When i try manually hitting the url in browser, it downloads the excel file under downloads folder. i have already tried this manually before.

 

So, Please let me know whether we can achieve it using readyAPi? 

 

Thanks

 

Highlighted
Community Hero

I am member like you, explore the problems,  see what works and suggest some solutions as part of that in spare time.

You may feel free to check with SmartBear customer support.



Regards,
Rao.
Highlighted
Community Hero

Hi @doubtsreadyapi,

Just a quick update. From your description what youre asking is entirely achievable in ReadyAPI!.

It appears that the dynamically generated URL you are building differs from the URL you are submitting in the browser.

1. Grab the URL you are submitting in the browser, plug it into a url decoder to remove the percent encoding (via https://www.url-encode-decode.com)

2. Submit the request in ReadyAPI!, go to the RAW tab and grab the URL that is generated. Plug this into the html encoder/decoder and decode to remove the percent encoding

3. Compare the browser URL which works against the one submitted in ReadyAPI! and tske note of the differences.

4. Update the config in ReadyAPI! so that the dynamically generated URL matches the format/pattern of the browser URL

Ta

Rich
if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
Highlighted
Community Hero

By the way, I can see the file downloaded in the temp directory(check attachments tab below response editor) when this is tried.

 

nmrao_0-1590815669958.png

Note, Download Resources checkbox ticked.

Explore what you are doing differently.



Regards,
Rao.
Highlighted
Contributor

@richie 

 

Thanks for the Information, I done get with the dynamic URL, with the HTTP method, Now i am getting the raw response as below, but i am not seeing any attachments tab under response,  I am not sure where the file got downloaded. Do you have any idea where the file got downloaded?

 

and i dont see any difference the url which i am posting in the browser and the dynamic url. only thing before i was doing POST request. for HTTP Request

 

HTTP/1.1 200 OK
Server: gunicorn/20.0.4
Date: Mon, 01 Jun 2020 05:34:41 GMT
Connection: close
Content-Disposition: attachment; filename=testing_AutoAPI_Dev_7505_20200601.xlsm
Content-Length: 338158
Content-Type: application/vnd.ms-excel.sheet.macroEnabled.12
Last-Modified: Mon, 01 Jun 2020 05:24:47 GMT
Cache-Control: public, max-age=43200
Expires: Mon, 01 Jun 2020 17:34:41 GMT
ETag: "1590989087.1710029-338158-1402026568"
Access-Control-Expose-Headers: Content-Disposition
Access-Control-Allow-Origin: *

 

doubtsreadyapi_0-1590990037083.png

 

Highlighted
Community Hero

Hey @doubtsreadyapi,

Ive never tested response attachments before, but ive a couple of points to raise that might help.

Firstly without any readyapi! config overriding the operating system id expect a file to be written to your usr profile somewhere or at least a temp directory.
Im not in front of my laptop right now to check but have you had a look in the Preferences to see if you have a default download directory set?
Have you tried searching your hard drive for the filename or part of the filename?
This leads me onto my next point. Is the file coming in as an attachment on the response OR is it actually embedded within the response as a payload? Reason i ask is that you state the attachments tab isnt available on your response and also your screenshot appears to display encoded data. If you cant find a file on your harddrive id suspect (considering your screenshot) that perhaps the response doesnt have an attachment.
Once im back in front of my laptop i'll have a quick google and look in my readyapi! settings and update this response but in the meantime can you check your settings and if file exists on you harddrive

Ta

Rich
if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
Highlighted
Contributor

Hey @richie 

 

Thanks for the detailed explanation, I have already checked whether the file is available in my local directory with the name, but i haven't found any file with the name and i have checked the preferences also there is no directory mentioned. 

 

 

 

 

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