Commit 63dcf18a authored by hewenhao's avatar hewenhao

feat: file upload key

parent 47cf87e9
...@@ -73,7 +73,7 @@ function uploadFile ({ fileName, filePath, relativePath }) { ...@@ -73,7 +73,7 @@ function uploadFile ({ fileName, filePath, relativePath }) {
cos.sliceUploadFile({ cos.sliceUploadFile({
Bucket: 'test-1257124244', // Bucket 格式:test-1250000000 Bucket: 'test-1257124244', // Bucket 格式:test-1250000000
Region: 'ap-chengdu', Region: 'ap-chengdu',
Key: getFileName(relativePath), Key: getFileName(relativePath, filePath),
ContentType: getContentType(filePath), ContentType: getContentType(filePath),
FilePath: filePath, FilePath: filePath,
}, function (err, data) { }, function (err, data) {
...@@ -93,12 +93,13 @@ function uploadFile ({ fileName, filePath, relativePath }) { ...@@ -93,12 +93,13 @@ function uploadFile ({ fileName, filePath, relativePath }) {
}) })
} }
function getFileName(filePath) { function getFileName(filePath, absolutPath) {
const str = require('crypto') const str = require('crypto')
.createHash('sha1') .createHash('sha1')
.update('geek-cos-upload') .update('geek-cos-upload')
.update('\0__1') .update('\0__1')
.update(filePath) .update(filePath)
.update(fs.readFileSync(absolutPath, { encoding: 'binary' }))
.digest('base64') .digest('base64')
.replace(/\.|\-|\=|\+|\//g, '_') .replace(/\.|\-|\=|\+|\//g, '_')
return `${str.substring(0, 4)}/${str.substring(4)}` 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