如题这个network.uploadFile是怎么用的,主要是不明白服务器端怎么接收,前端需要和服务器端定什么协议?
使用的是 HTTP POST
— Upload a file through a CCHTTPRequest instance.
– @author zrong(zengrong.net)
– Creation: 2014-04-14
– @param callback As same as the first parameter of network.createHTTPRequest.
– @param url As same as the second parameter of network.createHTTPRequest.
– @param datas Includes following values:
– fileFiledName(The input label name that type is file);
– filePath(A absolute path for a file)
– contentType(Optional, the file’s contentType, default is application/octet-stream)
– extra(Optional, the key-value table that transmit to form)
– for example:
network.uploadFile(function(evt)
if evt.name == "completed" then
local request = evt.request
printf("REQUEST getResponseStatusCode() = %d", request:getResponseStatusCode())
printf("REQUEST getResponseHeadersString() =\n%s", request:getResponseHeadersString())
printf("REQUEST getResponseDataLength() = %d", request:getResponseDataLength())
printf("REQUEST getResponseString() =\n%s", request:getResponseString())
end
end,
"http://127.0.0.1/upload.php",
{
fileFieldName="filepath",
filePath=device.writablePath.."screen.jpg",
contentType="Image/jpeg",
extra={
{"act", "upload"},
{"submit", "upload"},
}
}
)