简体   繁体   English

尝试从blobstore检索文件并使用谷歌应用引擎将其作为邮件附件发送

[英]trying to retrieve file from blobstore and send it as mail attachment using google app engine

I am trying to design an application that would require me to retrieve data stored in blobstore and send it as attachment. 我正在尝试设计一个应用程序,要求我检索存储在blobstore中的数据并将其作为附件发送。 Does google app engine allow this? 谷歌应用引擎是否允许这样做? From the documentation, i could not find a way to retrieve data from blobstore for processing within the app.. can someone please tell me how to accomplish this? 从文档中,我找不到从blobstore中检索数据以便在应用程序内处理的方法..有人可以告诉我如何完成此操作吗? Code examples and/or pointers to related online resources would be really helpful. 代码示例和/或相关在线资源的指针将非常有用。

As of now, it seems this isn't possible. 截至目前,似乎这是不可能的。 You can only cause the the file to be sent to the client . 您只能将文件发送到客户端

It's possible you could do what you need using a Datastore Blob ? 您可以使用Datastore Blob做您需要的工作吗?

It's worth also noting that the Blobstore is "experimental" and may change. 值得注意的是,Blobstore是“实验性的”并且可能会发生变化。 It's possible additional functionality may be added that would allow what you'r trying to do. 可能会添加额外的功能,允许您尝试执行的操作。

您现在可以使用BlobReader从blobstore读取数据, BlobReader提供了一个简单的,类似文件的界面。

You can use BlobstoreInputStream to do almost the same thing as BlobReader do. 您可以使用BlobstoreInputStream执行与BlobReader几乎相同的操作。

https://developers.google.com/appengine/docs/java/javadoc/com/google/appengine/api/blobstore/BlobstoreInputStream https://developers.google.com/appengine/docs/java/javadoc/com/google/appengine/api/blobstore/BlobstoreInputStream

BlobstoreInputStream provides an InputStream view of a blob in Blobstore. BlobstoreInputStream在Blobstore中提供blob的InputStream视图。 It is thread compatible but not thread safe: there is no static state, but any multithreaded use must be externally synchronized. 它是线程兼容的但不是线程安全的:没有静态,但任何多线程使用必须在外部同步。

This can be accomplished in two steps using the code from the Complete Sample App. 这可以使用Complete Sample App中的代码分两步完成。 http://code.google.com/appengine/docs/java/blobstore/overview.html#Complete_Sample_App http://code.google.com/appengine/docs/java/blobstore/overview.html#Complete_Sample_App

1) Write a servlet that takes a blobkey and returns the contents of the blob. 1)编写一个带有blobkey并返回blob内容的servlet。

public void doGet(HttpServletRequest req, HttpServletResponse res)
    throws IOException {
        BlobKey blobKey = new BlobKey(req.getParameter("blob-key"));
        blobstoreService.serve(blobKey, res);
    }

2) Within your application, use the URLFetchService.fetch(java.net.URL url) with the proper blobkey to retrieve the blob (as a stream) and attach it to the email. 2)在您的应用程序中,使用带有正确blobkey的URLFetchService.fetch(java.net.URL url)来检索blob(作为流)并将其附加到电子邮件中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM