Created
October 30, 2019 10:39
-
-
Save giasuddin90/e8dba40cb77eae28f6f6548b5f3e41a0 to your computer and use it in GitHub Desktop.
using python pyramid framework and post method.By providing file type and file name we we download file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| __author__ = 'giasuddin' | |
| from pyramid.view import view_config | |
| import os | |
| @view_config(request_method='POST', renderer='json') | |
| def post(self): | |
| file_type = self.request.matchdict['file_type'] | |
| node_type = self.request.matchdict['node_type'] | |
| sanitize_file = False | |
| if self.request.POST['files'].filename: | |
| filename = self.request.POST['files'].filename | |
| sanitize_file = filename | |
| input_file = self.request.POST['files'].file | |
| media_root = "/home/path/" + '/' + file_type + '/' + node_type | |
| if not os.path.exists(media_root): | |
| os.makedirs(media_root) | |
| file_path = os.path.join(media_root, sanitize_file) | |
| output_file = open(file_path, 'wb') | |
| data = input_file.read() | |
| output_file.write(data) | |
| output_file.close() | |
| return {'filename': sanitize_file} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment