Reputation: 1750
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...
Upvotes: 0
Views: 406
Reputation: 26
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.
Upvotes: 1