def documentUpload(): """ 上传文件并验证 https://zhuanlan.zhihu.com/p/23731819?refer=flask """ files = request.files['document'] filename = secure_filename(files.filename) if (files and Utils.allowed_file(filename)): path = os.getcwd() + "/uploads/" + filename files.save(path) return BaseController().error('你成功走通了') return BaseController().error('文件类型错误')
def upload(): f = request.files['file'] filename = secure_filename(f.filename) if (f and Utils.allowed_file(filename)): file_suffix = f.filename.split('.')[1] path = UPLOAD_FOLDER + Utils.unique_id() + '.' + file_suffix full_path = os.getcwd() + path f.save(full_path) return BaseController().successData(data={ 'path': path, 'name': f.filename }, msg='图片提交成功') return BaseController().error('文件类型不允许')
def upload(params): filename = secure_filename(params['name']) base64Data = params['dataUrl'].split(',')[1] if (base64Data and Utils.allowed_file(filename)): file_suffix = params['name'].split('.')[1] path = UPLOAD_FOLDER + Utils.unique_id() + '.' + file_suffix full_path = os.getcwd() + path f = open(full_path, 'wb') data = base64.b64decode(base64Data) f.write(data) #f.write(params['arrayBuffer']) f.close return Utils.formatBody({ 'path': path, 'name': filename }, msg='上传成功') return Utils.formatError(Code.BAD_REQUEST, '文件类型不允许')