我使用标准java文件流来上传文件。当我尝试上传 25MB 大小的 zip 文件时,花了将近 11 分钟。但当我尝试将该文件上传到 yousendit.com 一个文件上传网站时,只花了 25 秒。以下是我的代码
File file = new File(destination + fileName);
FileOutputStream fileOutputStream = new FileOutputStream(file);
byte[] buffer = new byte[1024];
InputStream in = dataHandler.getDataSource().getInputStream();
int len = in.read(buffer);
while (len != -1) {
fileOutputStream.write(buffer, 0, len);
len = in.read(buffer);
}
fileOutputStream.flush();
fileOutputStream.close();
我没有加快上传速度的想法?还有其他第 3 方 API 或其他建议吗?
最佳答案
您可以将文件分割成 block 并在单独的线程中上传每个 block 。据我所知,HTTP 标准定义了特殊的 header ,可以帮助服务器将 block 连接在一起。
从看FileUpload开始来自阿卡赫
关于java - Java Webservice 上传文件太慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16458940/