@@ -161,25 +161,41 @@ class S3Adapter {
161
161
getFileLocation ( config , filename ) {
162
162
const fileName = filename . split ( '/' ) . map ( encodeURIComponent ) . join ( '/' ) ;
163
163
if ( this . _directAccess ) {
164
+ let presignedUrl = '' ;
164
165
if ( this . _presignedUrl ) {
165
- const params = { Bucket : this . _bucket , Key : fileName , Expires : this . _presignedUrlExpires } ;
166
- return this . _s3Client . getSignedUrl ( 'getObject' , params ) ;
166
+ const params = {
167
+ Bucket : this . _bucket ,
168
+ Key : this . _bucketPrefix + fileName ,
169
+ Expires : this . _presignedUrlExpires ,
170
+ } ;
171
+ presignedUrl = this . _s3Client . getSignedUrl ( 'getObject' , params ) ;
167
172
}
168
173
if ( this . _baseUrl ) {
174
+ let directAccessUrl ;
175
+
169
176
if ( typeof this . _baseUrl === 'function' ) {
170
177
if ( this . _baseUrlDirect ) {
171
- return `${ this . _baseUrl ( config , filename ) } /${ fileName } ` ;
178
+ directAccessUrl = `${ this . _baseUrl ( config , filename ) } /${ fileName } ` ;
179
+ } else {
180
+ directAccessUrl = `${ this . _baseUrl ( config , filename ) } /${ this . _bucketPrefix + fileName } ` ;
172
181
}
173
- return `${ this . _baseUrl ( config , filename ) } /${ this . _bucketPrefix + fileName } ` ;
182
+ } else if ( this . _baseUrlDirect ) {
183
+ directAccessUrl = `${ this . _baseUrl } /${ fileName } ` ;
184
+ } else {
185
+ directAccessUrl = `${ this . _baseUrl } /${ this . _bucketPrefix + fileName } ` ;
174
186
}
175
- if ( this . _baseUrlDirect ) {
176
- return `${ this . _baseUrl } /${ fileName } ` ;
187
+
188
+ if ( this . _presignedUrl ) {
189
+ directAccessUrl += presignedUrl . substring ( presignedUrl . indexOf ( '?' ) + 1 ) ;
177
190
}
178
- return `${ this . _baseUrl } /${ this . _bucketPrefix + fileName } ` ;
191
+ return directAccessUrl ;
192
+ }
193
+ if ( this . _presignedUrl ) {
194
+ return presignedUrl ;
179
195
}
180
196
return `https://${ this . _bucket } .s3.amazonaws.com/${ this . _bucketPrefix + fileName } ` ;
181
197
}
182
- return ( `${ config . mount } /files/${ config . applicationId } /${ fileName } ` ) ;
198
+ return `${ config . mount } /files/${ config . applicationId } /${ fileName } ` ;
183
199
}
184
200
185
201
handleFileStream ( filename , req , res ) {
0 commit comments