How can I upload an thumbnail image (blob) at the same time as an Entity into a datastore in google app engine?

寵の児 提交于 2019-11-27 08:49:47

问题


I Just started using google app engine today, and I have fallen in love with endpoints. I made one very easily that will store an object in the datastore that just has a few string values. But I also want a small thumbnail image to go along with that datastore entity. I understand how to upload blobs from android using an HttpServlet. I was thinking of using the id of the datastore entity as the image's name in the blobstore, but I dont know how to connect the two events since I would upload the Entity to the datastore, and then the blob after that request. Does anyone know how I can get an image in the blobstore somehow connected to the entity in the datastore so when I access the datastore i can also recall the blob associated with it. Any help would be greatly appreciated!

Thanks, Zach


回答1:


Well you can use ImageService API in GAE to serve your images of different sizes and also you can apply various transformations on those images.

I am sharing you some code as well below so you will understand how I am serving the image urls using the stored blobkey.

String blobKeyString = blobKey.getKeyString();   // Returned value of blobkey when upload is done.
ImagesService services = ImagesServiceFactory.getImagesService();
ServingUrlOptions serve = ServingUrlOptions.Builder.withBlobKey(blobKey);
String imageUrl = services.getServingUrl(serve);


来源:https://stackoverflow.com/questions/15306790/how-can-i-upload-an-thumbnail-image-blob-at-the-same-time-as-an-entity-into-a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!