def complaint_file_upload(complaint_id): if request.method == 'PATCH': if 'file' not in request.files: return handle400() file = request.files['file'] if file.filename == '': return handle400() filename = upload_file(file) complaint = Complaint.query.filter_by(id=complaint_id).first() if complaint: complaint.file_name = filename db.session.commit() return complaint_file_upload_dto() else: return handle404() else: return handle405()
def upload_file(file): if file and allowed_file(file.filename): try: filename = secure_filename(time.strftime("%Y%m%d-%H%M%S-") + file.filename) file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) return filename except Exception as e: print(e) return handle500() else: return handle400()
def project_file_upload(project_id): if request.method == 'PATCH': if 'file' not in request.files: return handle400() file = request.files['file'] if file.filename == '': return handle400() filename = upload_file(file) project = Project.query.filter_by(id=project_id).first() if project: project.file_name = filename db.session.commit() return project_file_upload_dto() else: return handle404() else: return handle405()
def get_uploaded_file(filename): try: return send_from_directory(app.config['UPLOAD_FOLDER'], filename) except Exception as e: print(e) return handle400()