1

我设法创建了将带有“gwtuploaded”的图像上传到应用程序引擎并将图像存储为blob的功能。我现在的问题是:我从imagesService.getServingUrl(suo)链接到比我上传的图像小的图像的 url。如果我在应用引擎控制台的 blob 查看器中检查图像,它似乎具有正确的大小。

为什么我会使用以下代码获得调整大小的图像版本。我可以以某种方式检索全尺寸图像的网址吗?

我的代码如下所示:

public class MyUploadAction extends AppEngineUploadAction{

    @Override
    public String executeAction(HttpServletRequest request, List<FileItem> sessionFiles) throws UploadActionException {

        String imageUrls = "";

        // Image service is needed to get url from blob
        ImagesService imagesService = ImagesServiceFactory.getImagesService();

        // Get a file service -> write the blob
        FileService fileService = FileServiceFactory.getFileService();

        // Iterate over the files and upload each one
        for(FileItem myFile : sessionFiles){

            InputStream imgStream = null;
            // construct our entity objects
            Blob imageBlob = null;

            // Create a new Blob file with mime-type "image/png"
            AppEngineFile file = null;

            FileWriteChannel writeChannel = null;
            try {
                // get input stream from file
                imgStream = myFile.getInputStream();
                imageBlob = new Blob(IOUtils.toByteArray(imgStream));

                // create empty app engine file with mime type of uploaded file e.g.: image/png, image/jpeg
                file = fileService.createNewBlobFile(myFile.getContentType());

                // Open a channel to write to it
                boolean lock = true;
                writeChannel = fileService.openWriteChannel(file, lock);

                // This time we write to the channel directly
                writeChannel.write(ByteBuffer.wrap(imageBlob.getBytes()));

            } catch (IOException e) {
                e.printStackTrace();
            }finally{
                // Now finalize
                try {
                    writeChannel.closeFinally();
                } catch (IllegalStateException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

            }

            // Get the url from the blob
            ServingUrlOptions suo = ServingUrlOptions.Builder.withBlobKey(fileService.getBlobKey(file)).secureUrl(true);
            imageUrls += imagesService.getServingUrl(suo);
            imageUrls = imageUrls.replaceFirst("0.0.0.0", "127.0.0.1");
            System.out.println(imageUrls);

        }
        return imageUrls ;
    }
}
4

1 回答 1

1

我试过了,发现图像服务的最大图像输出为 1600x1600。看到这里并搜索 1600:https ://developers.google.com/appengine/docs/java/images/

即使您不要求调整大小,这也适用。

要以原始大小提供图像,您不应该使用图像服务,只需直接从(例如 blobstore)输出

于 2013-09-06T04:20:19.537 回答