使用Python Bottle服务器接收来自Android的POST请求的FileEntity
在 Android 手机上,我使用 setEntity() 将 FileEntity 放入 POST 请求。
HttpPost post = new HttpPost(uri);
FileEntity reqEntity = new FileEntity(f, "application/x-gzip");
reqEntity.setContentType("binary/octet-stream");
reqEntity.setChunked(true);
post.addHeader("X-AethersNotebook-Custom", configuration.getCustomHeader());
post.setEntity(reqEntity);
使用瓶子时,尝试了这个,但它不起作用
f = request.body
gzipper = gzip.GzipFile( fileobj= f )
content = gzipper.read()
内容将是一个空字符串。所以我尝试查看 request.forms 和 request.files。它们都没有键和值。
request.files.keys()
request.forms.keys()
在搜索时,我读到了有关该实体的信息:“请求可以传输实体”,并且该实体具有实体标头和实体值。所以它可能类似于 file-content = e.get(entity-header)。
On Android phone, I used setEntity() to put the FileEntity to the POST request.
HttpPost post = new HttpPost(uri);
FileEntity reqEntity = new FileEntity(f, "application/x-gzip");
reqEntity.setContentType("binary/octet-stream");
reqEntity.setChunked(true);
post.addHeader("X-AethersNotebook-Custom", configuration.getCustomHeader());
post.setEntity(reqEntity);
When using bottle, tried this but it is not working
f = request.body
gzipper = gzip.GzipFile( fileobj= f )
content = gzipper.read()
The content will be an empty string. So I tried to look at request.forms and request.files. Both of them have no key and value.
request.files.keys()
request.forms.keys()
When searching, I read about the entity: "a request MAY transfer entity" and the entity has entity-header and entity-value. So it may be something like file-content = e.get(entity-header).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用该代码,手机使用分块编码发送文件。因为 py-bottle 不支持分块编码,所以这里的解决方案是重写 android 以将文件作为 POST 请求的正文发送。
Using that code, the phone send file using chunked encoding. Because py-bottle does not support chunked enconding, the solution here is rewrite the android to send file as body of POST request.