Google Cloud Storageã«ä¿åããç»åããªãµã¤ãºãã¦å¿çããæ¹æ³
æè¿ã¯ã¹ãã¼ããã©ã³ã§æ®å½±ã§ããç»åã®è§£å度ã巨大åãã¦ãã®ã§ããã®ã¾ã¾ã表示ããã¨é
ããªã£ã¦ãã¾ãã
ããã§ããªã¯ã¨ã¹ããã©ã¡ã¼ã¿ã«widthã追å ãã¦ãä»»æã®ãµã¤ãºã§è¡¨ç¤ºã§ããããã«ããã
ããã§ã¯blobKeyãå ã«BlobInfoãæ±ãã¦ããã©ããã¡ã¤ã«åãå ã«ãããå ´å㯠makeImageFromFilename()ã§ãå¯è½ã
â« ImagesServiceFactory(Google App Engine API for Java) | Java の App Engine スタンダード環境 | Google Cloud
String key = request.getParameter("key"); String width = request.getParameter("width"); int w = 1024; try { w = Integer.parseInt(width); } catch (Exception e) {} BlobKey blobKey = new BlobKey(key); BlobInfo info = new BlobInfoFactory().loadBlobInfo(blobKey); Image image = ImagesServiceFactory.makeImageFromBlob(blobKey); Transform tf = ImagesServiceFactory.makeResize(w, w); Image resized = ImagesServiceFactory.getImagesService().applyTransform(tf, image); byte[] data = resized.getImageData(); String contentType = info.getContentType(); if (contentType == null || contentType.isEmpty()) { response.setContentType("application/octet-stream"); } else { response.setContentType(contentType); } response.setContentLength(data.length); ServletOutputStream os = response.getOutputStream(); os.write(data);