flask中文件上传的方法

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)
    

你可能感兴趣的:(flask中文件上传的方法)