1. Introduce ali-OSS file first

<script src="https://cdn.bootcdn.net/ajax/libs/ali-oss/6.13.2/aliyun-oss-sdk.js"></script>
Copy the code

2. Set parameters

let client = new OSS({
    region: "oss-cn-shenzhen".// The location of your OSS address is shown below
    accessKeyId: ' './ / your ak
    accessKeySecret: ' './ / your secret
    bucket: "www-yywh" // Your OSS name
});
Copy the code

3. It can then be uploaded to OSS

// The first type of normal upload
async function putObject () {
    try {
        // Object-key can be customized in the form of a file name (such as file.txt) or a directory (such as ABC /test/file.txt) to upload files to the current Bucket or a specified directory under the Bucket.
        let result = await client.put('test_img/1.jpg', file);
        console.log('success',result);
    } catch (e) {
        console.log('failure',e);
    }
}
putObject();
// The second type of block upload
client.multipartUpload("test_img" + "/1.jpg", file).then(function (result) {
    console.log('success',result);
}).catch(function (err) {
    console.log('wrong',err);
});
Copy the code