1. 程式人生 > >flask圖片上傳和下載

flask圖片上傳和下載

圖片上傳和顯示

上傳儲存

def save_to_local(file, file_name):         save_dir = app.config['UPLOAD_DIR']

        file.save(os.path.join(save_dir, file_name))

        return '/image/' + file_name

下載顯示

@app.route('/image/<image_name>')

def view_image(image_name):

        return send_from_directory(app.config['UPLOAD_DIR'], image_name)