Skip to content

Commit a5d2309

Browse files
committed
Fix minio accept externalEndPoint even in private bucket
1 parent 93e3328 commit a5d2309

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/minio.service.ts

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

111-
return await this.minioClient.presignedGetObject(
111+
const presignedUrl = await this.minioClient.presignedGetObject(
112112
bucketName,
113113
objectName,
114114
this.config.urlExpiryHours * 60 * 60,
115115
);
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;
116129
}
117130

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

0 commit comments

Comments
 (0)