Skip to content

Commit b1401ae

Browse files
committed
Fix presigning externalEndPoint causing issue
1 parent 0dba091 commit b1401ae

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

src/minio.service.ts

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -108,24 +108,30 @@ export class MinioService implements OnModuleInit {
108108
}/${bucketName}/${objectName}`;
109109
}
110110

111-
const presignedUrl = await this.minioClient.presignedGetObject(
111+
// For private buckets, if external endpoint is configured, create a new client with it
112+
if (this.config.externalEndPoint) {
113+
const externalClient = new Minio.Client({
114+
endPoint: this.config.externalEndPoint,
115+
port: this.config.port,
116+
useSSL: this.config.externalUseSSL ?? this.config.useSSL,
117+
accessKey: this.config.accessKey,
118+
secretKey: this.config.secretKey,
119+
region: this.config.region,
120+
});
121+
122+
return await externalClient.presignedGetObject(
123+
bucketName,
124+
objectName,
125+
this.config.urlExpiryHours * 60 * 60,
126+
);
127+
}
128+
129+
// If no external endpoint, use the default client
130+
return await this.minioClient.presignedGetObject(
112131
bucketName,
113132
objectName,
114133
this.config.urlExpiryHours * 60 * 60,
115134
);
116-
117-
// If external endpoint is configured, replace the internal endpoint with external endpoint in the URL
118-
if (this.config.externalEndPoint) {
119-
const urlObject = new URL(presignedUrl);
120-
urlObject.protocol = (this.config.externalUseSSL ?? this.config.useSSL) ? 'https:' : 'http:';
121-
urlObject.host = this.config.externalEndPoint;
122-
if (this.config.port) {
123-
urlObject.port = this.config.port.toString();
124-
}
125-
return urlObject.toString();
126-
}
127-
128-
return presignedUrl;
129135
}
130136

131137
async deleteFile(bucketName: string, objectName: string): Promise<void> {

0 commit comments

Comments
 (0)