@@ -11,6 +11,16 @@ const awsCredentialsDeprecationNotice = function awsCredentialsDeprecationNotice
11
11
'See: https://github.com/parse-server-modules/parse-server-s3-adapter#aws-credentials for details' ) ;
12
12
} ;
13
13
14
+ const serialize = ( obj ) => {
15
+ const str = [ ] ;
16
+ Object . keys ( obj ) . forEach ( ( key ) => {
17
+ if ( obj [ key ] ) {
18
+ str . push ( `${ encodeURIComponent ( key ) } =${ encodeURIComponent ( obj [ key ] ) } ` ) ;
19
+ }
20
+ } ) ;
21
+ return str . join ( '&' ) ;
22
+ } ;
23
+
14
24
class S3Adapter {
15
25
// Creates an S3 session.
16
26
// Providing AWS access, secret keys and bucket are mandatory
@@ -66,7 +76,7 @@ class S3Adapter {
66
76
67
77
// For a given config object, filename, and data, store a file in S3
68
78
// Returns a promise containing the S3 object creation response
69
- createFile ( filename , data , contentType ) {
79
+ createFile ( filename , data , contentType , options = { } ) {
70
80
const params = {
71
81
Key : this . _bucketPrefix + filename ,
72
82
Body : data ,
@@ -88,6 +98,13 @@ class S3Adapter {
88
98
if ( this . _encryption === 'AES256' || this . _encryption === 'aws:kms' ) {
89
99
params . ServerSideEncryption = this . _encryption ;
90
100
}
101
+ if ( options . metadata && typeof options . metadata === 'object' ) {
102
+ params . Metadata = options . metadata ;
103
+ }
104
+ if ( options . tags && typeof options . tags === 'object' ) {
105
+ const serializedTags = serialize ( options . tags ) ;
106
+ params . Tagging = serializedTags ;
107
+ }
91
108
return this . createBucket ( ) . then ( ( ) => new Promise ( ( resolve , reject ) => {
92
109
this . _s3Client . upload ( params , ( err , response ) => {
93
110
if ( err !== null ) {
0 commit comments