下载文件原先使用下面的代码:
S3Object object = s3.getObject(bucketName, fileKey);
S3ObjectInputStream objectContent = object.getObjectContent();
OutputStream out =null;
try {
response.setCharacterEncoding("utf-8");
response.setContentType("multipart/form-data");
response.setHeader("Content-Disposition",
"attachment;fileName=" + FileUtils.setFileDownloadHeader(request, downloadName));
out = response.getOutputStream();
byte[] buf = new byte[1024];
int len;
while ((len = objectContent.read(buf)) > 0) {
out.write(buf, 0, len);
}
response.flushBuffer();
s3 内有这么一个方法可以获取文件某一断数据:
etObjectRequest rangeRequest = new GetObjectRequest(bucketName, fileKey)
.withRange(start, end);
S3Object object = s3.getObject(rangeRequest);
S3ObjectInputStream objectContent = object.getObjectContent();
如果下载了某段数据,怎么整合起来形成一个完整文件? 思路应该是下载各个分片合并,或在某个临时文件后面追加内容?哪里有比较完整的代码吗?希望各位朋友能够帮忙解答
1
lmshl 2022-07-10 16:18:56 +08:00
https://docs.oracle.com/javase/7/docs/api/java/nio/channels/SeekableByteChannel.html
SeekableByteChannel position(long newPosition) // Sets this channel's position. |