开发者

Use Python bottle server to receive FileEntity of a POST request from Android

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());
开发者_JAVA百科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).


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜