You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have an API that returns files for some of the endpoints. I like to use Posting when I am messing around with it and trying out new ways to do things. I didn't see an easy way of writing the response to file, so I have been using a Post-response script that looks like this:
defon_response(response, posting) ->None:
content_disposition=response.headers.get("Content-Disposition")
ifcontent_dispositionand"attachment"incontent_disposition:
importrefrompathlibimportPath# Extract filename from Content-Dispositionmatch=re.search(r'filename="?(?P<filename>[^"]+)"?', content_disposition)
filename=match.group("filename") ifmatchelse"downloaded_file"# Ensure filename is safe enoughfilename=Path(filename).name# Set download directorydownload_dir=Path.cwd() /".downloads"download_dir.mkdir(exist_ok=True)
# Write content to filefile_path=download_dir/filenamefile_path.write_bytes(response.content)
It's obviously not robust enough for a production-ready feature, but it works for now. I would prefer if the app had a feature that did something like this that I could turn on in the options, or something like that.
The text was updated successfully, but these errors were encountered:
I have an API that returns files for some of the endpoints. I like to use Posting when I am messing around with it and trying out new ways to do things. I didn't see an easy way of writing the response to file, so I have been using a Post-response script that looks like this:
It's obviously not robust enough for a production-ready feature, but it works for now. I would prefer if the app had a feature that did something like this that I could turn on in the options, or something like that.
The text was updated successfully, but these errors were encountered: