url文件如何实现下载 (url怎么下载文件)

2023-06-02 03:00:44

1前端注意点:

a.*.v

b..api.js

*.js

2.后端通过取得的url,下载文件到固定文件夹

3.运行

4.下载码:

try{

//*********************url************************

response1.reset();

//response1.setContentType(" *** lication/x-msdownload");

response1.setHeader("contentDisposition","attachment;filename-"+ new String(filename.getBytes("gb2312"),"ISO8859-1"));

OSS ossClient = new OSSClientBuilder().build(ossendpoint, stsaccessKeyId, stsaccessKeySecret, stssecurityToken);

String objectName="upload/test/"+filename;

OSSObject object =ossClient.getObject(bucketName,objectName);

BufferedInputStream input =new BufferedInputStream(object.getObjectContent());

byte[] buffBytes =new byte[1024];

//OutputStream outputStream=response1.getOutputStream();

BufferedOutputStream outputStream=new BufferedOutputStream(new FileOutputStream(new File("d:/OSS/"+filename)));

int read=0;

while((read =input.read(buffBytes))!=-1) {

System.out.println("========");

outputStream.write(buffBytes,0,read);

}

outputStream.flush();

outputStream.close();//is.close();

input.close();

// 关闭OSSClient。

ossClient.shutdown();

} catch (Exception e) {

System.out.println("Failed:");

System.out.println("Error code: " + e.getMessage());

}

上一篇:发财树的养护方法,发财树四季养殖管理方法「发财树」
下一篇:twice队内分工 (twice成员分工)
相关文章