你好,非常感谢您的回复,我测试的过程如下,还请指点:
location = /new {
default_type text/plain;
content_by_lua_file conf/data.lua;
}
文件 data.lua
local cjson = require('cjson')
local CHUNK_SIZE = 4096
local MAX_LINE_SIZE = 512
local req = ngx.req.socket()
local dst = ngx.socket.tcp()
local ct = ngx.var.content_type
local cl = ngx.var.content_length
if not ct then
ngx.say('no header')
end
if type(ct) == "table" then
ct = ct[1]
end
local data = "">
ngx.say(string.len(data))
ngx.say(data)
测试命令:curl -F file1=@/root/a.txt 10.1.1.155/new
a.txt文件内容如下
this is a.txt's content
测试结果如下:
208
------------------------------640e35494b2c
Content-Disposition: form-data; name="file1"; filename="a.txt"
Content-Type: text/plain
this is a.txt's content
------------------------------640e35494b2c--
结果就是这样,其实文件内容只有23个字符,不可能content-length为208,
所以我通过nginx上传a.txt到fastdfs的时候,需要处理掉boundary等相关信息
在 2016-09-09 11:53:36,"Ming" <moonb...@gmail.com> 写道:
boundary的长度应该是在 Content-Length 里面的。你 post 文件的客户端有问题。下面是一个例子:
location / {
content_by_lua_block {
ngx.say(ngx.var.http_content_length)
ngx.req.read_body() -- explicitly read the req body
local data = "">
if data then
ngx.say(#data)
ngx.say(data)
end
}
}
HTTP/1.1 100 Continue
HTTP/1.1 200 OK
Server: openresty
Date: Fri, 09 Sep 2016 03:51:34 GMT
Content-Type: text/plain; charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
143
143
--------------------------47156d56093be8a9
Content-Disposition: form-data; name="test"
1234
--------------------------47156d56093be8a9--
可以看到 http_content_length 和 post body data 长度是一样的。
--
moonbingbing
haoyun-kgq
好的,这个我看过了,就是想改造下。
看来只能另想它法了,其实我已经想到了一个方法,不用全部缓存文件内容,就可以实现边receive边send,
就差测试了。这样就不受磁盘io的限制或内存的限制了,上传很高效的!
继续研究~
非常感谢~
在 2016-09-09 19:16:48,"Ming" <moonb...@gmail.com> 写道:
whs860603
什么样的方法
在 2016年9月10日星期六 UTC+8上午11:16:16,Gq K写道:
好的,这个我看过了,就是想改造下。
看来只能另想它法了,其实我已经想到了一个方法,不用全部缓存文件内容,就可以实现边receive边send,
就差测试了。这样就不受磁盘io的限制或内存的限制了,上传很高效的!
继续研究~
非常感谢~
在 2016-09-09 19:16:48,"Ming" <
moonbi...@gmail.com> 写道:
在 2016年9月9日 下午6:05,haoyun
<haoyu...@163.com>写道:
你好,非常感谢您的回复,我测试的过程如下,还请指点:
location = /new {
default_type text/plain;
content_by_lua_file conf/data.lua;
}
文件 data.lua
local cjson = require('cjson')
local CHUNK_SIZE = 4096
local MAX_LINE_SIZE = 512
local req = ngx.req.socket()
local dst = ngx.socket.tcp()
local ct = ngx.var.content_type
local cl = ngx.var.content_length
if not ct then
ngx.say('no header')
end
if type(ct) == "table" then
ct = ct[1]
end
local data = "">
ngx.say(string.len(data))
ngx.say(data)
a.txt文件内容如下
this is a.txt's content
测试结果如下:
208
------------------------------640e35494b2c
Content-Disposition: form-data; name="file1"; filename="a.txt"
Content-Type: text/plain
this is a.txt's content
------------------------------640e35494b2c--
结果就是这样,其实文件内容只有23个字符,不可能content-length为208,
所以我通过nginx上传a.txt到fastdfs的时候,需要处理掉boundary等相关信息
在 2016-09-09 11:53:36,"Ming" <
moonbi...@gmail.com> 写道:
boundary的长度应该是在 Content-Length 里面的。你 post 文件的客户端有问题。下面是一个例子:
location / {
content_by_lua_block {
ngx.say(ngx.var.http_content_length)
ngx.req.read_body() -- explicitly read the req body
local data = "">
if data then
ngx.say(#data)
ngx.say(data)
end
}
}
HTTP/1.1 100 Continue
HTTP/1.1 200 OK
Server: openresty
Date: Fri, 09 Sep 2016 03:51:34 GMT
Content-Type: text/plain; charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
143
143
--------------------------47156d56093be8a9
Content-Disposition: form-data; name="test"
1234
--------------------------47156d56093be8a9--
可以看到 http_content_length 和 post body data 长度是一样的。
在 2016年9月9日 上午10:46,haoyun
<haoyu...@163.com>写道:
大家好~
我想通过nginx将上传的文件再次上传到fastdfs,
我测试发现,post到nginx的数据是带有boundary的,而且Content-Length的值并不是实际上传文件的大小,
这样就得先全部解析post数据,去掉boundary后,才是文件实际大小,这样要么全部把数据加载进内存,要么写到文件,
就不能读取一点数据发送一点数据了,有什么好的方法吗?
非常感谢~
--
--
--
doujiang24
Hello
0312birdzhang
可以使用fastdfs的modify方法,先上传一个文件,然后偏移写入,等同于流的方式上传。
在 2016年9月9日星期五 UTC+8上午10:46:53,Gq K写道:
大家好~
我想通过nginx将上传的文件再次上传到fastdfs,
我测试发现,post到nginx的数据是带有boundary的,而且Content-Length的值并不是实际上传文件的大小,
这样就得先全部解析post数据,去掉boundary后,才是文件实际大小,这样要么全部把数据加载进内存,要么写到文件,
就不能读取一点数据发送一点数据了,有什么好的方法吗?
非常感谢~