Commit 63dcf18a authored by hewenhao's avatar hewenhao

feat: file upload key

parent 47cf87e9
......@@ -73,7 +73,7 @@ function uploadFile ({ fileName, filePath, relativePath }) {
cos.sliceUploadFile({
Bucket: 'test-1257124244', // Bucket 格式:test-1250000000
Region: 'ap-chengdu',
Key: getFileName(relativePath),
Key: getFileName(relativePath, filePath),
ContentType: getContentType(filePath),
FilePath: filePath,
}, function (err, data) {
......@@ -93,12 +93,13 @@ function uploadFile ({ fileName, filePath, relativePath }) {
})
}
function getFileName(filePath) {
function getFileName(filePath, absolutPath) {
const str = require('crypto')
.createHash('sha1')
.update('geek-cos-upload')
.update('\0__1')
.update(filePath)
.update(fs.readFileSync(absolutPath, { encoding: 'binary' }))
.digest('base64')
.replace(/\.|\-|\=|\+|\//g, '_')
return `${str.substring(0, 4)}/${str.substring(4)}`
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment