On Thu, Mar 1, 2012 at 11:25 PM, Jeff Schnitzer <[email protected]> wrote:
> On Thu, Mar 1, 2012 at 3:34 PM, Kayode Odeyemi <[email protected]> wrote: > >> To store upload images as blob using the filesystem api. Then be able >> to access the raw image files via a file/url resource path when >> wrapped around <img tag or accessed directly through the browser. >> > > Forget file paths. The only thing that matters is 1) getting your blob > into the blobstore, and 2) calling getServingUrl(). > > I got it resolved with this: FileService fileService = FileServiceFactory.getFileService(); AppEngineFile writableFile = fileService.createNewBlobFile(request.getParameter("qqfile")); FileWriteChannel writeChannel = null; try { byte[] buffer = new byte[4096]; // 4MB lock = true; writeChannel = fileService.openWriteChannel(writableFile, lock); // increase the buffer size as you are reading from the // input stream. Read the input stream into buffer for (int n; (n = stream.read(buffer)) != -1; ){ writeChannel.write(ByteBuffer.wrap(buffer)); } } finally { writeChannel.closeFinally(); } BlobKey blobKey = fileService.getBlobKey(writableFile); ImagesService imagesService = ImagesServiceFactory.getImagesService(); // produces something like http://localhost:8888/_ah/img/SU52WMsoCRP3kqAvQqVW3g String imageUrl = imagesService.getServingUrl(blobKey); Cool stuff! > -- > 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. > -- Odeyemi 'Kayode O. http://ng.linkedin.com/in/kayodeodeyemi. t: @charyorde blog: http://sinati.com/tree/java-cheat-sheet -- 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.
