flask中文件上传的方法
2018-10-18 本文已影响0人
Challis
upload_dir = os.path.join(BASE_DIR,'static/uploadfiiles/')
parser = reqparser.RequestParser()
parser.add_argument('img',type=werkzeug.datastructures.FileStorage, location='files',required=True, help='请选择图片')
class UploadFIles(Resource):
def post(self):
parse = parser.parse_args()
imgfile = parse.get('img')
filename = '%d-%s' % (user.id,secure_filename(imgfile.filename))
imgPath = os.path.join(upload_dir,filename)
imgfile.save(imgPath)