任何人都可以帮助我,我得到这个错误“ [Errno 2]没有这样的文件或目录:” 0b93397fa45180ee219aa69d3957daba.jpg”,如果有人有建议,我想在上传和显示后得到图片!
from uuid import uuid4
from flask import Flask, request, render_template, send_from_directory
from flask_uploads import UploadSet, configure_uploads, IMAGES
import io
from google.cloud import vision
app = Flask(__name__)
# app = Flask(__name__, static_folder="images")
os.environ["GOOGLE_APPLICATION_CREDENTIALS"]="json_key.txt"
APP_ROOT = os.path.dirname(os.path.abspath(__file__))
@app.route("/")
def index():
return render_template("upload.html")
@app.route("/upload", methods=["POST"])
def upload():
target = os.path.join(APP_ROOT, 'images/')
# target = os.path.join(APP_ROOT, 'static/')
print(target)
if not os.path.isdir(target):
os.mkdir(target)
else:
print("Couldn't create upload directory: {}".format(target))
print(request.files.getlist("file"))
for upload in request.files.getlist("file"):
print(upload)
print("{} is the file name".format(upload.filename))
filename = upload.filename
destination = "/".join([target, filename])
print ("Accept incoming file:", filename)
print ("Save it to:", destination)
upload.save(destination)
with io.open(filename,'rb') as image_file:
content = image_file.read()
image = vision_client.image(content=content)
labels = image.detect_labels()
# return send_from_directory("images", filename, as_attachment=True)
return render_template("complete_display_image.html", image_name=filename,labels=labels)
@app.route('/upload/<filename>')
def send_image(filename):
return send_from_directory("images", filename)
if __name__ == "__main__":
app.run(port=5000, debug=True)