简体   繁体   English

在GAE BlobStore中旋转图像

[英]Rotating an image in the GAE BlobStore

I'm trying to rotate an image that is in the blobstore and then save it back to the blobstore, but I can't figure out how to save it back to the blobstore? 我正在尝试旋转blobstore中的图像,然后将其保存回blobstore,但是我不知道如何将其保存回blobstore? I did find this , but it looks like the FileService API is deprecated, so what do I use instead? 我确实找到了 ,但好像FileFile API已弃用,那么我该怎么用呢? Here's my code so far: 到目前为止,这是我的代码:

// Get image from blobstore
Image img = ImagesServiceFactory.makeImageFromBlob(new BlobKey(document.blobstoreKey));

// Rotate 90 degrees
Transform transform = ImagesServiceFactory.makeRotate(90);
img = ImagesServiceFactory.getImagesService().applyTransform(transform, img);

// HERE: How to save back to the blobstore?
...

Unfortunately, you're running into one the limitations of blobstore as documented at https://cloud.google.com/appengine/docs/java/blobstore/ ...: 不幸的是,您遇到了blobstore的局限性,如https://cloud.google.com/appengine/docs/java/blobstore/ ...所述:

An application cannot create or modify Blobstore values except through files uploaded by the user. 除通过用户上传的文件外,应用程序无法创建或修改Blobstore值。

...and that's exactly what you want to do -- create a blobstore value, not by having the user upload a file, but rather by saving the byte[] returned by img.getImageData() . ...而这正是您要执行的操作-创建blobstore值,而不是让用户上传文件,而是保存img.getImageData()返回的byte[]

If you're in control of the client (Javascript app on the browser) you could hack some trick around this, sending the bytes down to the browser and having Javascript immediately turn around and "upload" the new blobstore. 如果您控制客户端(浏览器上的Javascript应用程序),则可以解决此问题,将字节发送给浏览器,并让Javascript立即转身并“上传”新的Blobstore。 But this is really hacky -- and inherently slow, adding a "round trip" to the browser and back for potentially large-ish image data. 但这确实是很棘手的,而且本质上很慢,给浏览器增加了“往返”功能,并返回了可能很大的图像数据。

Rather, in your shoes, I'd take this as one more inducement to leave blobstore behind and move instead to google cloud storage -- specifically https://cloud.google.com/appengine/docs/java/googlecloudstorageclient/ . 相反,我想以此为诱因,将blobstore抛在后面,而转移到Google云存储-特别是https://cloud.google.com/appengine/docs/java/googlecloudstorageclient/

With GCS, you could for example just use the service's createOrReplace method, documented at https://cloud.google.com/appengine/docs/java/googlecloudstorageclient/javadoc/ , passing it a ByteBuffer.wrap of that byte[] , and voila, it's all done for you, simply, rapidly, without complications. 例如,使用GCS,您可以只使用服务的createOrReplace方法,该方法在https://cloud.google.com/appengine/docs/java/googlecloudstorageclient/javadoc/中进行了说明 ,并将该byte[]ByteBuffer.wrap传递给它,然后瞧,这一切都为您完成了,简单,快速,无并发症。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM