// 创建 OSS 客户端对象 createOssClientTemp () { return new Promise((resolve) => { let client = new OSS({ accessKeyId: 'xxx', accessKeySecret: 'xxx', bucket: 'xxx' }) resolve(client) }) }, // OSS 文件下载 ossDownloadFile (objectKey) { this.createOssClientTemp().then( client => { let url = client.signatureUrl(objectKey, { response: { 'content-disposition': 'attachment; filename="' + name + '.' + type + '"' }, expires: 3600 }) console.log(url) window.location.href = url }) }
Ps:一般 OSS 下载都会遇到跨域文件下载问题,当然有时候如果电脑有安装下载检测浏览器时,可以避免,但是为了考虑周全,还是要想一个通用的办法。
注意事项