gpt4 book ai didi

android - 使用 Python bottle server 接收来自 Android 的 POST 请求的 FileEntity

转载 作者:太空宇宙 更新时间:2023-11-04 06:26:42 26 4
gpt4 key购买 nike

在 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);

当使用 Bottle 时,尝试过这个但它不起作用

f = request.body
gzipper = gzip.GzipFile( fileobj= f )
content = gzipper.read()

内容将是一个空字符串。所以我试着查看 request.forms 和 request.files。它们都没有键和值。

request.files.keys()
request.forms.keys()

在搜索时,我读到了实体:“请求可以传输实体”并且该实体具有实体 header 和实体值。所以它可能类似于 file-content = e.get(entity-header)。

最佳答案

使用该代码,手机使用分块编码发送文件。因为py-bottle不支持chunked enconding,这里的解决方案是重写android以发送文件作为POST请求的主体。

关于android - 使用 Python bottle server 接收来自 Android 的 POST 请求的 FileEntity,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7527413/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com