将图像临时存储在 Google App Engine 中?
我正在用Python编写一个应用程序,它将每2小时检查一个网站(我们称之为A)上的更新,如果有新帖子,它会下载帖子中的图像并将其发布到另一个网站(称之为A) B),然后删除这些图像。 B站提供了上传图片的API,并附有描述,如下:upload(image_path, description)
,其中 image_path
是图像在计算机上的路径。
现在我已经完成了该应用程序,我正在尝试使其在 Google App Engine 上运行(因为我的计算机无法运行 7x24),但似乎 GAE 不允许您在其文件系统上写入文件。< br> 我该如何解决这个问题?或者还有其他免费 Python 托管并提供“cron job”功能的选择吗?
I'm writing an app with Python, which will check for updates on a website(let's call it A) every 2 hours, if there are new posts, it will download the images in the post and post them to another website(call it B), then delete those images.
Site B provide API for upload images with description, which is like:upload(image_path, description)
, where image_path
is the path of the image on your computer.
Now I've finished the app, and I'm trying to make it run on Google App Engine(because my computer won't run 7x24), but it seems that GAE won't let you write files on its file system.
How can I solve this problem? Or are there other choices for free Python hosting and providing "cron job" feature?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
GAE 有一个 BlobStore API,它可以像文件存储一样工作,但可能不是您想要的。实际上,正确的答案取决于您使用的 API 类型 - 它可能支持类似文件的对象,因此您可以传递 urllib 响应对象,或接受 URL,或大量其他有趣的功能
GAE has a BlobStore API, which can work pretty much as a file storage, but probably it's not what you whant. Actually, the right answer depends on what kind of API you're using - it may support file-like objects, so you could pass urllib response object, or accept URLs, or tons of other interesting features
您根本不需要使用临时存储 - 只需使用 urlfetch 将图像下载到内存中,然后使用另一个 urlfetch 将其上传到目标站点即可。
You shouldn't need to use temporary storage at all - just download the image with urlfetch into memory, then use another urlfetch to upload it to the destination site.