Storing rotated / flipped images in Google App Engine

后端 未结 1 1317
情话喂你
情话喂你 2020-12-16 23:26

I\'m trying to rotate / flip an image that is already sitting inside Google Cloud Storage.

This is the blobkey:

BlobKey blobKey = new BlobKey(upload.         


        
相关标签:
1条回答
  • 2020-12-16 23:51

    To override the original image, you simply need to specify the same Cloud Storage filename.

    I understand that you have uploaded the image to Cloud Storage through App Engine via the BlobStore API. To get the actual filename of the original image, you must add the following code in the upload servlet :

      Map<String,List<BlobInfo>> uploadInfos = getFileInfos(httpServletRequest);
      String theGCSFilename = uploadInfos.get("yourFileName").getGsObjectName();
    

    Note that if you do not want to overwrite the original file, but want to provide a serving URL to the customer, you can either :

    • Use the ImageService like this :

      ImagesService imagesService = ImagesServiceFactory.getImagesService();
      String url = imagesService.getServingUrl(ServingUrlOptions.Builder.withGoogleStorageFileName(java));
      
    • Create a custom GCSServingServlet who will use the BlobstoreService.serve() method to serve a file from the Blobstore or Cloud Storage. In that case, you must check the permissions yourself. Note that you can create a BlobKey from a GCSFilename using BlobStoreService.createGSBlobKey().

    • Use the Cloud Storage serving URLs :

      • Private : http://commondatastorage.googleapis.com/bucket/filename
      • Public : http://storage.googleapis.com//bucket/filename
    0 讨论(0)
提交回复
热议问题