【问题标题】:App Engine Blobstore/ImageService - Served image has not the original sizeApp Engine Blobstore/ImageService - 提供的图像没有原始大小
【发布时间】:2013-09-08 14:41:10
【问题描述】:

我设法创建了将带有“gwtuploaded”的图像上传到应用引擎并将图像存储为 blob 的功能。我现在的问题是:我从imagesService.getServingUrl(suo) 获得的网址链接到比我上传的图片小的图片。如果我在应用引擎控制台的 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 ;
    }
}

【问题讨论】:

  • 通过代码我假设你正在你的开发集群中测试这个?您如何确定图像的尺寸有误,是视觉上的吗?浏览器调整图像大小以在屏幕上完全显示它们?您是否将任何选项附加到生成的网址?

标签: image google-app-engine gwt upload blobstore


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-11-16
    • 1970-01-01
    • 2013-12-25
    • 1970-01-01
    • 1970-01-01
    • 2015-07-03
    • 2014-04-04
    • 2014-05-05
    相关资源
    最近更新 更多