GAE-处理外部URI

时间:2018-07-26 18:23:20

标签: python google-app-engine pdf

我正在尝试在GAE flexible上处理URI,特别是我正在通过pdf2image处理pdf文件。 每当我在pdf2image的convert_from_path上使用URI时,GAE都会抛出

  

找不到文件

,但是如果我在本地计算机上执行相同的过程,则该过程将正确执行。 我是否应该在Google App Engine上进行设置以允许它?

1 个答案:

答案 0 :(得分:4)

这个pdf在哪里?

您的标题显示为“外部URI”,但是pdf2image的{​​{1}}文档似乎表明此文件位于您的代码中。

如果文件确实位于项目代码中并随项目一起部署,请尝试使用此文件将相对路径转换为绝对路径:

convert_from_path

编辑:

对于GCS上的pdf,我将单独处理从gcs进行的下载,然后使用curr_dir = os.path.dirname(os.path.realpath(__file__)) images = convert_from_path(curr_dir+'/my/relative/path/example.pdf') 代替convert_from_bytes

您将像这样设置与GCS的连接:

https://cloud.google.com/appengine/docs/flexible/python/using-cloud-storage

使用此函数获取GCS blob:

https://googlecloudplatform.github.io/google-cloud-python/latest/storage/buckets.html#google.cloud.storage.bucket.Bucket.get_blob

然后使用此功能实际下载字节:

https://googlecloudplatform.github.io/google-cloud-python/latest/storage/blobs.html#google.cloud.storage.blob.Blob.download_as_string

是这样的:

convert_from_path