0
votes

I create an imageServing url over an image file uploaded on Google cloud storage using :

String key = "/gs/<bucket-name>/<path>";
ImagesService imagesService = ImagesServiceFactory.getImagesService();
ServingUrlOptions options = ServingUrlOptions.Builder
                .withGoogleStorageFileName(key)
                .imageSize(900) // Optional.
                .crop(true); // Optional.
String servingUrl = imagesService.getServingUrl(options);

But there does not seem to be a method to delete this url. The available method "deleteServingUrl" accepts a blobKey, which I do not use.

Does this mean I do not need to delete the servingUrl ?

///////EDIT

Using Appengine with objectify. Created a servlet, UserImageEndpoint Defined it in web.xml as :

<servlet>
    <servlet-name>UserImageEndpoint</servlet-name>
    <servlet-class>reach.backend.Servlets.UserImageEndpoint</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>UserImageEndpoint</servlet-name>
    <url-pattern>/userImageEndpoint</url-pattern>
</servlet-mapping>

Servlet class :

public class UserImageEndpoint extends HttpServlet {

private static final Logger logger = Logger.getLogger(UserImageEndpoint.class.getName());
private static final String BUCKET_NAME_IMAGE = "xxxx-yyyy";


@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    //
    //
    //
    GcsFilename gcsFilename = new GcsFilename(BUCKET_NAME_IMAGE, actualImageId);
    GcsService gcsService = GcsServiceFactory.createGcsService();
    //this works, I get the meta-data, hence I am able to access
    logger.info(gcsService.getMetadata(gcsFilename).toString());
    BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
    BlobKey blobKey = blobstoreService.createGsBlobKey(
                        "/gs/" + gcsFilename.getBucketName() + "/" + gcsFilename.getObjectName());
    logger.info("Requesting fileName - " + blobKey.getKeyString());
    servingURL = ImagesServiceFactory.getImagesService().getServingUrl(
                        ServingUrlOptions.Builder.withBlobKey(blobKey));

Last line crashes with :

java.lang.IllegalArgumentException: ACCESS_DENIED: at com.google.appengine.api.images.ImagesServiceImpl.getServingUrl(ImagesServiceImpl.java:282)

//////EDIT Ling no. 282 seems to be the method deleteServingUrl(BlobKey blobKey), which I am not even calling right now...

1
lmgtfy: Whether you store your images in Blobstore or Google Cloud Storage, the right way to stop an image from being publicly accessible through the serving URL is to call the deleteServingUrl() method. If you merely delete the underlying stored image from Blobstore or Google Cloud Storage , under some circumstances the image may remain accessible through the serving URL. (Source: cloud.google.com/appengine/docs/java/images/…) - konqi
But I do not have a blobKey as I am using "withGoogleStorageFileName" - Dexter
BlobKey blobKey = blobstoreService.createGsBlobKey( "/gs/" + fileName.getBucketName() + "/" + fileName.getObjectName()); (Source: cloud.google.com/appengine/docs/java/blobstore/…) - konqi
@konqi hey I am getting ACCESS_DENIED when using this, although I am able to access the file using a "GcsService". - Dexter
please provide what code you have so far. Also note the Important section in cloud.google.com/appengine/docs/java/images. - konqi

1 Answers

1
votes

As @konqi points out the Important-section in the docs state that you can not get a serving url if the file has already been made publicly available through Cloud Storage (cloud.google.com/appengine/docs/java/images)

I had the exact same issue but resolved it by not setting ACL to public in cloud storage before trying to create a serving url using the Blobstore API.