def upload(): """ 上传图片 """ logger.info('url = ' + str(request.url)) if request.method == "POST" and "file" in request.files: # 文件对象 f = request.files.get("file") # 文件名 filename = rename_image(f.filename) # 保存 f.save(os.path.join(current_app.config["ALBUMY_UPLOAD_PATH"], filename)) # 小图 # 在resize_image函数中,会保存图片 filename_s = resize_image( f, filename, current_app.config["ALBUMY_PHOTO_SIZE"]["small"] ) # 中图 filename_m = resize_image( f, filename, current_app.config["ALBUMY_PHOTO_SIZE"]["medium"] ) # 保存图片对象 photo = Photo( filename=filename, filename_s=filename_s, filename_m=filename_m, author=current_user._get_current_object(), ) logger.info('上传文件,{},{},{}'.format(filename, filename_m, filename_s)) # 提交 db.session.add(photo) db.session.commit() return render_template("main/upload.html")
def upload(): if request.method == 'POST' and 'file' in request.files: f = request.files.get('file') filename = rename_image(f.filename) f.save(os.path.join(current_app.config['ALBUMY_UPLOAD_PATH'], filename)) filename_s = resize_image(f, filename, current_app.config['ALBUMY_PHOTO_SIZE']['small']) filename_m = resize_image(f, filename, current_app.config['ALBUMY_PHOTO_SIZE']['medium']) photo = Photo(filename=filename, filename_s=filename_s, filename_m=filename_m, author=current_user._get_current_object()) db.session.add(photo) db.session.commit() return render_template('main/upload.html')
def upload(): if request.method == "POST" and "file" in request.files: f = request.files.get("file") filename = rename_image(f.filename) f.save(os.path.join(current_app.config["ALBUMY_UPLOAD_PATH"], filename)) filename_s = resize_image( f, filename, current_app.config["ALBUMY_PHOTO_SIZE"]["small"]) filename_m = resize_image( f, filename, current_app.config["ALBUMY_PHOTO_SIZE"]["medium"]) photo = Photo(filename=filename, filename_s=filename_s, filename_m=filename_m, author=current_user._get_current_object()) db.session.add(photo) db.session.commit() return render_template("main/upload.html")