File tree Expand file tree Collapse file tree 2 files changed +6
-9
lines changed Expand file tree Collapse file tree 2 files changed +6
-9
lines changed Original file line number Diff line number Diff line change @@ -3,11 +3,7 @@ const fileService = require('../services/fileService')
3
3
async function upload ( ctx ) {
4
4
const fileToUpload = ctx . request . files . file
5
5
const currentUser = ctx . request . jwtPayload . sub
6
- const { key, url } = await fileService . uploadFile ( {
7
- fileName : fileToUpload . name ,
8
- filePath : fileToUpload . path ,
9
- fileType : fileToUpload . type
10
- } )
6
+ const { key, url } = await fileService . uploadFile ( fileToUpload )
11
7
await fileService . setTags ( key , [ { Key : 'username' , Value : `${ currentUser } ` } ] )
12
8
ctx . body = { key, url }
13
9
}
@@ -21,6 +17,7 @@ async function download (ctx) {
21
17
}
22
18
23
19
const fileData = await fileService . downloadFile ( fileToDownload )
20
+ ctx . set ( 'Content-Type' , fileData . ContentType )
24
21
ctx . body = fileData . Body
25
22
}
26
23
Original file line number Diff line number Diff line change @@ -49,19 +49,19 @@ const getTags = async key => {
49
49
} )
50
50
}
51
51
52
- const uploadFile = async ( { fileName , filePath , fileType } ) => {
52
+ const uploadFile = async ( fileObject ) => {
53
53
return new Promise ( ( resolve , reject ) => {
54
54
getS3Ref ( )
55
- const stream = fs . createReadStream ( filePath )
55
+ const stream = fs . createReadStream ( fileObject . path )
56
56
stream . on ( 'error' , err => {
57
57
reject ( err )
58
58
} )
59
59
60
60
s3 . upload ( {
61
61
Bucket : process . env . BUCKET ,
62
62
Body : stream ,
63
- Key : fileName ,
64
- ContentType : fileType
63
+ Key : fileObject . name ,
64
+ ContentType : fileObject . type
65
65
} ,
66
66
( err , data ) => {
67
67
if ( err ) {
You can’t perform that action at this time.
0 commit comments