Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
cos-uploader
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hewenhao
cos-uploader
Commits
63dcf18a
Commit
63dcf18a
authored
May 06, 2021
by
hewenhao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: file upload key
parent
47cf87e9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
3 additions
and
2 deletions
+3
-2
index.js
index.js
+3
-2
No files found.
index.js
View file @
63dcf18a
...
...
@@ -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
)}
`
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment