Java 从不推荐的Blobstore文件API到服务Blob

Java 从不推荐的Blobstore文件API到服务Blob,java,android,google-app-engine,google-cloud-endpoints,blobstore,Java,Android,Google App Engine,Google Cloud Endpoints,Blobstore,我正在使用谷歌应用程序引擎端点与我的Android应用程序连接。在我的一个端点中,我有一个方法,它获取一个用Base64编码的图像,然后存储在Blobstore中。检索图像是通过GoogleImageService的服务URL完成的 所以,我有两个问题。首先,我使用的Blobstore文件API已被弃用。第二,调用速度非常慢,因为服务器在存储blob时同步工作,稍后再提供url和blob密钥 所以我的问题是,我如何更改代码以使用(servlet)提出的Blobstore,但在Android代码中

我正在使用谷歌应用程序引擎端点与我的Android应用程序连接。在我的一个端点中,我有一个方法,它获取一个用Base64编码的图像,然后存储在Blobstore中。检索图像是通过GoogleImageService的服务URL完成的

所以,我有两个问题。首先,我使用的Blobstore文件API已被弃用。第二,调用速度非常慢,因为服务器在存储blob时同步工作,稍后再提供url和blob密钥

所以我的问题是,我如何更改代码以使用(servlet)提出的Blobstore,但在Android代码中继续使用我非常好的端点。有没有一种方法可以在不使用HttpRequest类的情况下继续使用该方法

简言之:

  • 我可以保留对端点的客户端调用,还是需要更改该代码
  • 如果我可以保留端点的客户端/服务器端接口,那么如何重定向到Blobstore以异步保存映像,然后调用另一个servlet来存储blobkey和服务url
  • 这是我的密码

    从Android客户端发送到Google app engine的实体

    @Entity
    public class Image {
    
        @Id
        private int id = -1;
        private byte[] data;
        private String mimeType;
        private int width;
        private int height;
    
        public int getId() {
            return id;
        }
    
        public void setId(int id) {
            this.id = id;
        }
    
        public byte[] getData() {
            return data;
        }
    
        public void setData(byte[] data) {
            this.data = data;
        }
    
        public String getMimeType() {
            return mimeType;
        }
    
        public void setMimeType(String mimeType) {
            this.mimeType = mimeType;
        }
    
        public int getWidth() {
            return width;
        }
    
        public void setWidth(int width) {
            this.width = width;
        }
    
        public int getHeight() {
            return height;
        }
    
        public void setHeight(int height) {
            this.height = height;
        }
    }
    
    服务器端端点实现:

    @Api(name = "imageEndpoint", namespace = @ApiNamespace(ownerDomain = "example.com", ownerName = "example.com", packagePath = "myPackage")}
    public class ImageEndPoint extentds BaseEndPoint {
    
        @ApiMethod(name = "updateImage")
        public Void updateImage(final User user,
                final Image image) {
    
            String blobKey = FileHandler.storeFile(
                    location != null ? location.getBlobKey() : null,
                    image.getData(), image.getMimeType(),
                    LocationTable.TABLE_NAME + "." + locationId, logger);
            ImagesService imageService = ImagesServiceFactory
                    .getImagesService();
    
            // image size 0 will retrieve the original image (max: 1600)
            ServingUrlOptions options = ServingUrlOptions.Builder
                    .withBlobKey(new BlobKey(blobKey)).secureUrl(true)
                    .imageSize(0);
    
            String servingUrl = imageService.getServingUrl(options);
    
            // store BlobKey & ServingUrl in Database
    
            return null;
        }
    }
    
    Android Java代码调用Google应用程序引擎上的端点

    public void uploadBitmap(Bitmap image)
    {
        ImageEndpoint.Builder endpointbuilder = creator.create(
                AndroidHttp.newCompatibleTransport(), new JacksonFactory(),
                new HttpRequestInitializer() {
    
                    @Override
                    public void initialize(HttpRequest arg0)
                            throws IOException {
                    }
                });
    
        endpointbuilder.setApplicationName(GoogleConstants.PROJECT_ID);
        ImageEndpoint endpoint = endpointbuilder.build();
    
        // set google credidentials
    
        // encode image to byte-rray
        byte[] data = ....
    
        // create cloud contet
        Image content = new Image();
        content.setWidth(image.get_width());
        content.setHeight(image.get_height());
        content.setMimeType("image/png");
        content.setData(Base64.encodeBase64String(data));
    
        // upload content (but takes too much time)
        endpoint.updateImage(content);
    }
    

    这并不是您解释的问题解决方案,但您可以使用以下GCS:

    有很多谷歌云存储java api可用,你可以上传图像或任何文件,你可以制作并获取图像url,或者从GCS获取JSON api,这样你就可以下载图像或任何文件内容

    例:

    您可以使用谷歌云存储将数据发送到云端和服务器

    在android中使用谷歌云存储来检索数据


    将其移植到谷歌云存储的例子是否可以接受?您之所以使用文件API,是因为您希望通过端点上传图像(例如使用Android摄像头拍摄的照片),还是因为其他原因?另外,您是在应用程序的其他地方使用图像服务来转换图像,还是仅使用图像服务来处理原始图像?(您发布的代码只服务于未转换的图像,这可以在没有图像服务的情况下完成。)我使用两个图像服务URL。一个是原始图像,另一个是将图像缩小到320x240。我想继续使用端点,但我也可以改为servlet。但是我需要一个使用端点方法中使用的Google用户的示例。这是一个注入参数,如果它不是端点,我不知道在Android上添加它。这是因为不是每个用户都可以在我的应用程序中上传图片。看起来很有希望。我会试一试,然后告诉你。