我正在尝试创建一个将上传的图像转换为pdf文件的烧瓶应用程序。 我可以使用下面的代码生成带有图像的PDF。如何从谷歌应用引擎上托管的Flask返回生成的PDF?
from fpdf import FPDF
pdf = FPDF()
img = input('enter file name')
g = img + '.jpg'
pdf.add_page()
pdf.image(g, 50, 50)
pdf.output(img + '.pdf', 'F')
下面是在blobstore中上传和存储图像的代码
from flask import Flask, redirect, render_template, request, Response, url_for
from google.appengine.ext import ndb
from google.appengine.api import images
from fpdf import FPDF
import os
app = Flask(__name__)
class Image(ndb.Model):
blob = ndb.BlobProperty()
mimetype = ndb.StringProperty()
alt = ndb.StringProperty()
caption = ndb.TextProperty()
@app.route('/')
def render_form():
return render_template('/form.html')
@app.route('/upload', methods=['POST'])
def handle_upload():
image = Image(
alt=request.form.get('alt'),
caption=request.form.get('caption')
)
uploaded_file = request.files.get('file')
image.mimetype = uploaded_file.mimetype
image_data = uploaded_file.stream.read()
image.blob = images.resize(image_data, 256, 256)
image.put()
return redirect(url_for('serve_image', id=image.key.urlsafe()))
@app.route('/img/<id>')
def serve_image(id):
image_key = ndb.Key(urlsafe=id)
image = image_key.get()
return Response(image.blob, mimetype=image.mimetype)
那么如何将上传的图像文件(存储在blobstore中)转换为pdf
实际上谷歌应用引擎不允许在临时文件夹中上传图像,我们必须首先在blobstore上传,这就是为什么我要问如何将图像(存储在blobstore中)转换为pdf。请帮助我