【发布时间】:2009-12-15 22:58:43
【问题描述】:
我想从诺基亚手机上传一个大文件到服务器,我使用下面的代码。此代码适用于小文件。当我想上传一个更大的文件(大约 10mb)时,我会收到一条内存不足的消息。有谁知道如何转换此代码以使用上传文件 多个 httpConnections,每个连接发送一个文件块。假设服务器支持这一点。
fc = (FileConnection)Connector.open("file:///myfile", Connector.READ);
is = fc.openInputStream();
// opening http connection and outputstream
HttpConnection http = (HttpConnection)Connector.open(url, Connector.WRITE);
http.setRequestMethod(HttpConnection.POST);
http.setRequestProperty("Content-Type", type);
http.setRequestProperty("Connection", "close");
OutputStream os = http.openOutputStream();
int total = 0;
while (total < fileSize) {
byte b[] = new byte[1024];
int length = is.read(b, 0, 1024);
os.write(b, 0, length);
total += length;
}
os.flush();
int rc = http.getResponseCode();
os.close();
http.close();
【问题讨论】: