Thanks for the fast response Vinny,
Here are the definitions for the BLOB_STORE and IMAGES_SERVICE variables.
private static final BlobstoreService BLOB_STORE =
BlobstoreServiceFactory.getBlobstoreService();
private static final ImagesService IMAGES_SERVICE =
ImagesServiceFactory.getImagesService();
I have also tried using ServingUrlOptions.Builder.withGoogleStorageFileName
with the same result of IllegalArgumentException with no error message.
public static String getNotFoundUrl(int size) {
try {
// BlobKey blob_key =
BLOB_STORE.createGsBlobKey("/gs/web_content/placeholder_img.png");
// byte[] image_data = BLOB_STORE.fetchData(blob_key, 0, 100);
// Application.getLogger().warning(new String(image_data));
ServingUrlOptions opts =
ServingUrlOptions.Builder.withGoogleStorageFileName("/gs/web_content/placeholder_img.png");
if(size > 0) opts.imageSize(size);
return IMAGES_SERVICE.getServingUrl(opts);
} catch(IllegalArgumentException e) {
Application.getLogger().warning("Unable to serve placeholder image
from Cloud Storage.");
Application.getLogger().warning(e.getMessage());
Application.logException(e);
return "/placeholder_img.png";
}
}
One interesting thing to note is that the file was uploaded using the Cloud
Console Web UI and not through app engine sdk. Could that be what's causing
the problem?
On Monday, June 17, 2013 2:20:01 PM UTC-6, Vinny P wrote:
>
> Hello Dennis,
>
> Just to be clear the variable BLOB_STORE in your code represents the Files
> API accessing Google Cloud Storage, correct? Can you post that code as
> well?
>
> Secondly, if you are using Google Cloud Storage to save your images in,
> then you need to use a different function to create your ServingUrlOptions.
> Instead of using ServingUrlOptions.Builder.withBlobKey (which is reserved
> for images coming from AppEngine's Blobstore), you need to use
> ServingUrlOptions.Builder.withGoogleStorageFileName (files from GCS).
> Here's the relevant documentation:
> https://developers.google.com/appengine/docs/java/javadoc/com/google/appengine/api/images/ServingUrlOptions.Builder.
>
>
> -----------------
> -Vinny P
> Technology & Media Advisor
> Chicago, IL
>
> My Go side project: http://invalidmail.com/
>
>
> On Mon, Jun 17, 2013 at 3:02 PM, dennis wrote:
>
>> Here's the code:
>>
>> public static String getNotFoundUrl(int size) {
>> try {
>> BlobKey blob_key =
>> BLOB_STORE.createGsBlobKey("/gs/web_content/placeholder_img.png");
>>
>> // Simple Test to make sure blob_key points at the right thing.
>> byte[] image_data = BLOB_STORE.fetchData(blob_key, 0, 100);
>> Application.getLogger().warning(new String(image_data));
>> // This parts works and gets the first 100 bytes.
>>
>> ServingUrlOptions opts =
>> ServingUrlOptions.Builder.withBlobKey(blob_key);
>> if(size > 0) opts.imageSize(size);
>> return IMAGES_SERVICE.getServingUrl(opts);
>> } catch(IllegalArgumentException e) {
>> Application.getLogger().warning("Unable to serve placeholder image
>> from Cloud Storage.");
>> Application.getLogger().warning(e.getMessage());
>> Application.logException(e);
>> return "/placeholder_img.png";
>> }
>> }
>>
>> The fetchData call succeeds and I successfully read the first 100 bytes
>> of the file that way. But the getServingUrl fails with
>> IllegalArgumentException.
>>
>> java.lang.IllegalArgumentException:
>> at
>> com.google.appengine.api.images.ImagesServiceImpl.getServingUrl(ImagesServiceImpl.java:282)
>>
>>
>> Any ideas on why this happens will be much appreciated.
>>
>>
>
>
--
You received this message because you are subscribed to the Google Groups
"Google App Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-appengine.
For more options, visit https://groups.google.com/groups/opt_out.