oss以流的形式在浏览器下载想存到任意路径时,会出现错误,用上面的方式设置Header信息可以解决.
response.reset();
response.setContentType("application/x-msdownload");
response.setHeader("Content-Disposition","attachment;filename=" + new String(fileName.getBytes("gb2312"),"ISO8859-1"));
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>oss下载<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
OSSClient ossClient = new OSSClient(endpoint, accessKeyId, accessKeySecret);
key = fileUrl.toString();
key = key.replaceAll("\\\\", "/");
OSSObject object = ossClient.getObject(bucketName, key);
BufferedInputStream input = new BufferedInputStream(object.getObjectContent());
byte[] buffBytes = new byte[1024];
OutputStream outputStream = response.getOutputStream();
int read = 0;
while ((read = input.read(buffBytes)) != -1) {
outputStream.write(buffBytes, 0, read);
}
outputStream.flush();
outputStream.close();
//is.close();
input.close();
ossClient.shutdown();