App Engine Blobstore / ImageService - 提供的图像没有原始大小

时间:2013-09-04 22:30:00

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

我设法创建了将带有“gwtuploaded”的图像上传到app引擎并将图像存储为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 ;
    }
}

1 个答案:

答案 0 :(得分:1)

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

即使您没有要求调整大小,也适用。

要以原始尺寸投放图片,您不应该使用图片服务,只需直接从(例如blobstore)输出