Skip to content

Commit 3eeef95

Browse files
committed
Add getPresignedURL method on client
1 parent 174e6d5 commit 3eeef95

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,15 @@ client.downloadFile(filePathToRead, filePathToSave, createDirIfNotExists);
9090
- **filePathToSave** : Path to save in file system
9191
- **createDirIfNotExists** : Boolean to create the folder if the it doesn't exists. Default is `true`
9292

93+
### Get Pre-signed URL for private files
94+
95+
```js
96+
client.getPresignedURL(path, expires);
97+
```
98+
99+
- **path** : Path for the file to get the pre-signed URL
100+
- **expires** : Time to expire the pre-signed URL (in seconds) (defaults to 900 seconds / 15 minutes);
101+
93102
## License
94103

95104
MIT © Bruno Orlandi

src/index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ class SpacesClient {
5858
return url.replace(/digitaloceanspaces/, 'cdn.digitaloceanspaces');
5959
}
6060

61+
async getPresignedURL(path, expires = 900) {
62+
return this.s3client.getSignedUrlPromise('getObject', {
63+
Bucket: this.bucket,
64+
Key: path,
65+
Expires: expires,
66+
});
67+
}
68+
6169
async isFilePublic(filePath) {
6270
const acl = await this.s3client.getObjectAcl({
6371
Bucket: this.bucket,

0 commit comments

Comments
 (0)