java - 无法用 Java 上传 200mb PDF 文件
问题描述
我能够上传具有 7MB 数据的 PDF 文件,但我无法上传超过 7MB 的数据。谁能提供如何使用 SMB 协议上传 200MB 文件同时使用 Angular 代码处理 200MB PDF 文件的示例
服务代码:
SmbFileOutputStream sfos = new SmbFileOutputStream(efbiFile);
byte[] buf = new byte[1024 * 1024 * 200];
BufferedOutputStream bufos = new BufferedOutputStream(sfos,buf.length);
final ReadableByteChannel inputChannel =
Channels.newChannel(fileObj.getInputStream());
final WritableByteChannel outputChannel = Channels.newChannel(bufos);
ChannelTools.fastChannelCopy(inputChannel,outputChannel);
inputChannel.close();
outputChannel.close();
解决方案
您很可能不想分配 200 MB 缓冲区 ( new byte[1024 * 1024 * 200]
)。的目的BufferedOutputStream
是提高许多小写入的整体性能,而不是将整个输入存储在 RAM 中。
您可以使用InputStream.transferTo(OutputStream )
方法并从默认BufferedOutputStream
大小 8196 开始:
try (InputStream in = fileObj.getInputStream();
SmbFileOutputStream sfos = new SmbFileOutputStream(efbiFile);
BufferedOutputStream out = new BufferedOutputStream(sfos)) {
in.transferTo(out);
out.flush(); // In case SmbFileOutputStream doesn't implement this correctly
}
推荐阅读
- c# - 数字签名入门 - 如何在 C# 中上传数字签名?
- c# - Azure 函数上的 CNTK
- javascript - vuejs 使用 fetch Api 获取 projects.json 的数据:Unexpected token < in JSON at position 0
- vuetify.js - 如何更改 v-data-table 中的值
- javascript - 无法使用 Angular 7 读取以下 JSON
- angular - 角度动态模型绑定不起作用
- javascript - 过滤对象中的多个值
- google-cloud-platform - Bigquery Transfert 工具错误 - “无效的机器类型 dts-eu 在区域 europe-west1-b: googleapi”
- python - 在 python 中设置字典时会发生什么?
- excel - 如果偏移值 = TRUE,则工作表上的 MSG 宏会更改