作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
所以,我正在上传一个文件,然后下载它...但是上传 header 中的 Content-Length 与文件大小不匹配。我猜这个计算和传输还涉及一些其他数据,但具体是什么?如何从 Content-Length 中获取准确的文件大小?有可能吗?
我知道有界限,也许还有一些其他的东西,但是检查一下:
5380216 - 5379906 = 310
"----WebKitFormBoundaryeoFyqD4zr6smwYDG".size
→ 38
所以边界大小是 38...310 有一些 LCD 为 5、10、31...这些在任何方面都不适合 38...我迷路了!
文件大小:
-rw-r--r--@ 1 williamcotton staff 5379906 Jul 2 12:02 testfile-downloaded.zip
-rw-r--r--@ 1 williamcotton staff 5379906 Jun 8 14:23 testfile-uploaded.zip
HTTP header
{
host: 'localhost:8887',
connection: 'keep-alive',
'content-length': '5380217',
'cache-control': 'max-age=0',
origin: 'http://localhost:8887',
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/22.0.1193.0 Safari/537.1',
'content-type': 'multipart/form-data; boundary=----WebKitFormBoundaryeoFyqD4zr6smwYDG',
accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
referer: 'http://localhost:8887/',
'accept-encoding': 'gzip,deflate,sdch',
'accept-language': 'en-US,en;q=0.8',
'accept-charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3'
}
tl;博士
文件大小为 5379906
Content-Length 报告为 5380216
为什么?
最佳答案
我认为 multipart/form-data 请求的每个部分都计入主要 Content-Length header 的总体大小。
找到这个作为引用: http://chxo.com/be2/20050724_93bf.html
所以,也许在你的标题之后,你可能有:
----WebKitFormBoundaryeoFyqD4zr6smwYDG
Content-Disposition: form-data; name="file"; filename="testfile-downloaded.zip"; size=<file size could be here>
Content-Length: <file size could also be here>
<some other content headers>
<file data>
----WebKitFormBoundaryeoFyqD4zr6smwYDG
所有这些都将计入 Content-Length 大小。
编辑
刚刚意识到我没有回答你的问题。不确定如何从请求的文件部分提取文件大小。对不起!
关于http - 从多部分表单上传 Content-Length header 获取文件大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11300641/
我有以下正则表达式 /[a-zA-Z0-9_-]/ 当字符串只包含从 a 到z 大小写、数字、_ 和 -。 我的代码有什么问题? 能否请您向我提供一个简短的解释和有关如何修复它的代码示例? //var
我是一名优秀的程序员,十分优秀!