
class AliyunUpload {
    static readonly REGION = 'oss-cn-chengdu'
    static readonly ACCESS_KEY_ID = 'LTAIwE7l9dImZSa3'
    static readonly ACCESS_KEY_SECRET = 'j47Ajn0d0WzUCIX8Biyj3P2r8QDltI'
    static readonly BUCKET = 'vt-im-bucket'

    static GetOSS = () => {
        const OSS = require('ali-oss');
        //return new OSS
        return new OSS({
            region:this.REGION,
            accessKeyId:this.ACCESS_KEY_ID,
            accessKeySecret:this.ACCESS_KEY_SECRET,
            bucket:this.BUCKET
        })
    }

    static UploadAsync = async (file:any,name:string)=>{
        try {
            const oss = this.GetOSS()
            const headers = {
                'Cache-Control':'public,max-age=31536000'
            };
            let result = await oss.put(name,file,{headers})
            return 'https://im.oytour.com/'+name//result.url
        } catch (error) {
            return ''
        }
    }
}

export default AliyunUpload