Aadith Ramia
Aadith Ramia

Reputation: 10329

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. 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? Code examples and/or pointers to related online resources would be really helpful.

Upvotes: 3

Views: 1162

Answers (4)

Antony.H
Antony.H

Reputation: 965

You can use BlobstoreInputStream to do almost the same thing as BlobReader do.

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

BlobstoreInputStream provides an InputStream view of a blob in Blobstore. It is thread compatible but not thread safe: there is no static state, but any multithreaded use must be externally synchronized.

Upvotes: 0

SingleNegationElimination
SingleNegationElimination

Reputation: 156148

You can now read data from the blobstore, using BlobReader, which provides a simple, file-like interface.

Upvotes: 2

Stevko
Stevko

Reputation: 4485

This can be accomplished in two steps using the code from the 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.

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.

Upvotes: 0

Danny Tuppeny
Danny Tuppeny

Reputation: 42333

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?

It's worth also noting that the Blobstore is "experimental" and may change. It's possible additional functionality may be added that would allow what you'r trying to do.

Upvotes: 2

Related Questions