如何从流Android的位图到谷歌应用程序引擎的Servlet? [英] How to stream Bitmap from Android to Google App Engine Servlet?
问题描述
我挣扎了几天这个问题,你是我最后的机会解决它。
I'm struggling for few days with this problem and you are my last chance solving it.
目标:
要上传的Android客户端,以谷歌应用程序引擎的位图,并将其保存在数据存储中。
To upload a bitmap from android client to google app engine and save it in datastore.
- 我使用序列化从客户端转移对象服务器,反之亦然。
的东西我曾尝试:
- 发送一个位图
- 但我得到了
java.io.NotSerializableException:android.graphics.Bitmap
- sending a Bitmap
- but i got
java.io.NotSerializableException: android.graphics.Bitmap
然后我想在这样的客户端从位图斑点创建:
then I tried create from the Bitmap Blob at the client like this:
ByteArrayOutputStream bos = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, bos); Byte[] bArray = bos.toByteArray(); Blob blob = new Blob(bArray);
但在客户端我没有谷歌的应用程序引擎类(BLOB),所以我试图用蛮力提取特定类新力量,但它创造了新的问题。
But at the client side I dont have the google app engine classes (for Blob), So I tried to brute force it by extract specific classess but it created new problems.
于是我问其中dierction我可以去从解决这个问题。结果
谢谢。So I am asking in which dierction I can go from to solve this problem.
Thanks.推荐答案
几点注意事项:
-
不要使用Java序列化到JVM之间传输数据。 Java序列化不规范,并且不保证(即使版本之间或)JVM之间不兼容。
Do not use Java serialization to transfer data between JVMs. Java serialization is not standardized and is not guaranteed to be compatible between JVMs (or even between versions).
要发送二进制数据,最好使用HTTP POST和设置
内容类型
适当地(例如应用程序/八位字节流
)。To send binary data it's best to use HTTP POST and set
Content-Type
appropriately (e.g.application/octet-stream
).因此,为了使这项工作做到这一点:
So, to make this work do this:
-
创建用于处理POST和得到的二进制数据的servlet。使用
的servletRequest。的getInputStream()
得到的二进制数据保持。
Create a servlet which handles POST and gets the binary data. Use
servletRequest.getInputStream()
to get hold of binary data.
使用Blob存储<一个href=\"https://developers.google.com/appengine/docs/java/blobstore/overview#Writing_Files_to_the_Blobstore\"相对=nofollow>的FileService API 来将数据保存到Blob存储区。
Use Blobstore FileService API to save data to blobstore.
在Android端使用 http客户端一>做一个POST请求和你的位图的二进制数据添加到它。如果您需要添加一些元数据,使用HTTP标头。
On Android side use a http client to make a POST request and add your bitmap's binary data to it. If you need to add some metadata use Http headers.
这篇关于如何从流Android的位图到谷歌应用程序引擎的Servlet?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
- but i got
- 但我得到了