Hi,
You can't stream data from App Engine. The response is buffered
until your servlet returns before sending the response.
http://code.google.com/appengine/docs/java/runtime.html#Responses
You might want to look at using the Blobstore. As Simon mentioned,
check out the FileService, perhaps it would be useful for building the
blobs.
Robert
On Wed, Apr 6, 2011 at 08:23, Kayode Odeyemi <[email protected]> wrote:
> Hello,
> In a nutshell, since GAE cannot write to a filesystem, I have decided to
> persist my data into the
> datastore (using JDO). Now, I will like to retrieve the data byte by byte
> and pass it to the client
> as an input stream. There's code from the gwtupload library (see below)
> which breaks on GAE
> because it writes to the system filesystem. I'll like to be able to provide
> a GAE ported solution.
>
> public static void copyFromInputStreamToOutputStream(InputStream in,
> OutputStream out) throws IOException {
> byte[] buffer = new byte[100000];
> while (true) {
> synchronized (buffer) {
> int amountRead = in.read(buffer);
> if (amountRead == -1) {
> break;
> }
> out.write(buffer, 0, amountRead);
> }
> }
> in.close();
> out.flush();
> out.close();
> }
> One work around I have tried (didn't work) is to retrieve the data from the
> datastore as a resource like this:
> InputStream resourceAsStream = null;
> PersistenceManager pm = PMF.get().getPersistenceManager();
> try {
> Query q = pm.newQuery(ImageFile.class);
> lf = q.execute();
> resourceAsStream = getServletContext().getResourceAsStream((String)
> pm.getObjectById(lf));
> } finally {
> pm.close();
> }
> if (lf != null) {
> response.setContentType(receivedContentTypes.get(fieldName));
> copyFromInputStreamToOutputStream(resourceAsStream,
> response.getOutputStream());
> }
> I welcome your suggestions.
> Regards
> --
> Odeyemi 'Kayode O.
> http://www.sinati.com
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google App Engine" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/google-appengine?hl=en.
>
--
You received this message because you are subscribed to the Google Groups
"Google App Engine" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-appengine?hl=en.