nodejs 阿里oss删除图片

const OSS = require('ali-oss')
let client = new OSS({
        region: 'oss-cn-najing',
        accessKeyId: 'youid',
        accessKeySecret: 'yoursecret',
        bucket: 'yourbucket',
        secure:true //    secure:配合 region使用。如果指定 securetrue,则使用 HTTPS 访问,不配置,调用下面get方法,则看到为htttp开头
});
//删除图片
async function del(url) {
    let result = await client.delete(url);
}
//获取图片
async function get(url) {
    let result = await client.get(url);
}
假如访问的img路径为: = https://yourbucket.oss-cn-nanjing.aliyuncs.com/20170909/pictures/156289727680779.png
则  const url =' 20170909/pictures/156289727680779.png';//object-name
     get(url);
    

 

     del(url)
删除后在访问图片,
NoSuchKey
The specified key does not exist.
5D29DF5FAE3689BFBB2CBA5B
yourbuket.oss-cn-nanjing.aliyuncs.com
20170909/pictures/156289727680779.png
 
阿里云文档地址:https://help.aliyun.com/document_detail/111408.html?spm=a2c4g.11186623.6.1217.140c4a

 

 

转载于:https://www.cnblogs.com/qiyc/p/11180613.html

你可能感兴趣的:(nodejs 阿里oss删除图片)