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.

On 3/1/12, Jeff Schnitzer <j...@infohazard.org> wrote:
> What are you trying to do?
>
> Jeff
>
> On Thu, Mar 1, 2012 at 2:29 PM, Kayode Odeyemi <drey...@gmail.com> wrote:
>
>> 2012/3/1 Ronoaldo José de Lana Pereira <rpere...@beneficiofacil.com.br>
>>
>>> Hello Odeyemi,
>>>
>>> If I got your problem right, yes, you can use the Files API to create an
>>> image blob, then use the ImageService to create a dedicated URL to serve
>>> that image as Jeff said. You can safely cache the generated URL, it will
>>> be
>>> available as long as you don't delete de blob.
>>>
>>> Double check that you called the closeFinally as documented here when
>>> creating the blob, and use the method
>>> getBlobKey<http://code.google.com/intl/en/appengine/docs/java/javadoc/com/google/appengine/api/files/FileService.html#getBlobKey%28com.google.appengine.api.files.AppEngineFile%29>from
>>> the Files api to get the blob key after you finalize your file. You
>>> can then use this to call the ImageService.getServingUrl(). This proccess
>>> works for both your unit tests and the local dev server.
>>>
>>> I think I implemented this just exactly the way you guys described it:
>>
>> Here's the code I'm working it:
>>
>> @RequestMapping(method=RequestMethod.POST)
>>     public void handleFileRequest(HttpServletRequest request,
>> HttpServletResponse response) throws Exception {
>>         Assert.notNull(request, "HttpServletRequest required");
>>
>>         // get the POST data
>>         Map files = request.getParameterMap();
>>         Iterator iter = files.values().iterator();
>>         List<Object> gg = new ArrayList<Object>();
>>         while(iter.hasNext()) {
>>             gg.add(iter.next());
>>         }
>>
>>         log.log(Level.INFO, "Parameter values are {0}",
>> request.getParameter("qqfile"));
>>
>>         InputStream stream = request.getInputStream();
>>         FileService fileService = FileServiceFactory.getFileService();
>>         AppEngineFile writableFile = null;
>>
>>         for(Object s : gg) {
>>             writableFile = fileService.createNewBlobFile(s.toString());
>>         }
>>         //writableFile =
>> fileService.createNewBlobFile(request.getParameter("qqfile"));
>>
>>         // Open a channel to write to it
>>         boolean lock = false;
>>         FileWriteChannel writeChannel =
>> fileService.openWriteChannel(writableFile, lock);
>>         ByteBuffer buffer = ByteBuffer.allocateDirect(stream.available());
>>         lock = true;
>>         writeChannel = fileService.openWriteChannel(writableFile, lock);
>>         writeChannel.write(buffer);
>>         writeChannel.closeFinally();
>>
>>         // get the created files path and pass to PrintWriter
>>         // Now read from the file using the Blobstore API
>>         BlobKey blobKey = fileService.getBlobKey(writableFile);
>>         BlobstoreService blobStoreService =
>> BlobstoreServiceFactory.getBlobstoreService();
>>
>>         // MAX_BLOB_FETCH_SIZE = 1015808
>>         String segment = new String(blobStoreService.fetchData(blobKey,
>> 30, 1024));
>>
>>         ImagesService imagesService =
>> ImagesServiceFactory.getImagesService();
>>         String imageUrl = imagesService.getServingUrl(blobKey);
>>         log.log(Level.INFO, "Imgae url is {0}", imageUrl);
>>
>>         response.setContentType("application/json; charset=UTF-8");
>>         PrintWriter out = response.getWriter();
>>         out.write("{\"result1\" : " + '\"' + writableFile.getFullPath() +
>> '\"' + "}");
>>
>> When the file was sent, it wasn't sent with the full path to the file. I
>> only got the filename + extension. Something like: file-name.jpg. So I
>> just
>> simply used that to create the new blob file.
>>
>> Perhaps I might be doing something wrong. I stand to be corrected.
>>
>> Thanks
>>
>>>
>>> Em quinta-feira, 1 de março de 2012 14h19min41s UTC-3, drecute escreveu:
>>>
>>>> On Thu, Mar 1, 2012 at 3:03 PM, Jeff Schnitzer
>>>> <j...@infohazard.org>wrote:
>>>>
>>>>> Look at the documentation for the images service.  There is a method
>>>>> that gives you a serving url directly to the CDN.
>>>>>
>>>>> Warning:  This method has a surprising amount of latency, you probably
>>>>> want to cache the value in memcache for a reasonable duration.
>>>>>
>>>>> Can the Image Service work with the filesystem where the blob is
>>>> stored? Everytime I try to retrieve it using the method you mentioned
>>>> getServingUrl(blobkey), I get the error:
>>>>
>>>> [java] java.lang.**IllegalArgumentException: Failed to read image
>>>> [java]     at com.google.appengine.api.**images.ImagesServiceImpl.**
>>>> getServingUrl(**ImagesServiceImpl.java:222)
>>>>
>>>> Also, I'm think this action is not possible on the dev server.
>>>>
>>>>>
>>>>> On Thu, Mar 1, 2012 at 7:42 AM, Kayode Odeyemi
>>>>> <drey...@gmail.com>wrote:
>>>>>
>>>>>> Hi everyone,
>>>>>>
>>>>>> I have images uploaded to the blobstore using filesystem API. The
>>>>>> files have been uploaded successfully and I can see the blobs in the
>>>>>> respective directory.
>>>>>>
>>>>>> But then, how do I decode these files such that when sent back to the
>>>>>> client or retrieved using the blobstore API, I'm able to get an image?
>>>>>> Right now /blobstore/writable:xxx is not useful for me because when I
>>>>>> wrap
>>>>>> the path in <img src="/blobstore/writable:xxx" />, it doesn't give me
>>>>>> an
>>>>>> image.
>>>>>>
>>>>>> Any help is appreciated.
>>>>>>
>>>>>> Thanks
>>>>>>
>>>>>>
>>>>>> --
>>>>>> Odeyemi 'Kayode O.
>>>>>> http://ng.linkedin.com/in/**kayodeodeyemi<http://ng.linkedin.com/in/kayodeodeyemi>.
>>>>>> t: @charyorde blog:
>>>>>> http://sinati.com/tree/java-**cheat-sheet<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 google-appengine@googlegroups.**
>>>>>> com <google-appengine@googlegroups.com>.
>>>>>> To unsubscribe from this group, send email to
>>>>>> google-appengine+unsubscribe@**googlegroups.com<google-appengine%2bunsubscr...@googlegroups.com>
>>>>>> .
>>>>>> For more options, visit this group at http://groups.google.com/**
>>>>>> group/google-appengine?hl=en<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 google-appengine@googlegroups.**
>>>>> com <google-appengine@googlegroups.com>.
>>>>> To unsubscribe from this group, send email to
>>>>> google-appengine+unsubscribe@**googlegroups.com<google-appengine%2bunsubscr...@googlegroups.com>
>>>>> .
>>>>> For more options, visit this group at http://groups.google.com/**
>>>>> group/google-appengine?hl=en<http://groups.google.com/group/google-appengine?hl=en>
>>>>> .
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> Odeyemi 'Kayode O.
>>>> http://ng.linkedin.com/in/**kayodeodeyemi<http://ng.linkedin.com/in/kayodeodeyemi>.
>>>> t: @charyorde blog:
>>>> http://sinati.com/tree/java-**cheat-sheet<http://sinati.com/tree/java-cheat-sheet>
>>>>
>>>>  --
>>> You received this message because you are subscribed to the Google Groups
>>> "Google App Engine" group.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msg/google-appengine/-/uX0cs5hKeoEJ.
>>>
>>> To post to this group, send email to google-appengine@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> google-appengine+unsubscr...@googlegroups.com.
>>> 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 google-appengine@googlegroups.com.
>> To unsubscribe from this group, send email to
>> google-appengine+unsubscr...@googlegroups.com.
>> 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 google-appengine@googlegroups.com.
> To unsubscribe from this group, send email to
> google-appengine+unsubscr...@googlegroups.com.
> 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 google-appengine@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.

Reply via email to