'how to return any file present in directory as a part of curl GET call
I am using tornado framework and trying implementing static file download functionality (I know we can use like below by specifying static_url_prefix so It will create handler and whenever we will use curl -0 -o nzcli -k https://127.0.0.1:8443/v2/download/testdata then It'll download testdata from where I am running script).
self.application = tornado.web.Application( self.url_all,
static_url_prefix=f"/{version}/download/",
static_path=str(static_path), )
But above implementation does not required username and password so I have decided to create separate handler for this like below.
@class_logger
class Static_file(AuthHandler):
URL_PATTERN = r"/(v\d+)/download_handler/([A-Za-z0-9_.]+)"
def do_get(self,ver,file_passed):
try:
print("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^")
static_path= pathlib.Path(pkg_resources.resource_filename("folder.app.data", "web"))
files = [ f for f in os.listdir(static_path) if os.path.isfile(os.path.join(static_path,f)) ]
print("All files in dir2 : ", files)
if file_passed in files:
pass //return file(It can be of any extension) to enter user(show progress in terminal)
else:
pass
status="File Downloading Completed."
return HTTPResponse(200, 'OK',status)
except Exception as exp:
status_code = 500
return HTTPResponse(status_code, str(exp),500)
Now My requirement is that whenever user send GET request that is
`curl -k -X GET https://127.0.0.1:PORT/v2/download_handler/testdata -H "Authorization:`cat /ips/abc/token`" -H "Content-Type: application/json"
with filename so that filename I will check if file_passed in files: but how to download file and show progress to the user from where he is running script.
any suggestions/solution would be highly appreciated. Thanks.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
