Skip to content

Commit

Permalink
Add getPresignedURL method on client
Browse files Browse the repository at this point in the history
  • Loading branch information
nihey committed Aug 25, 2020
1 parent 174e6d5 commit 3eeef95
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ client.downloadFile(filePathToRead, filePathToSave, createDirIfNotExists);
- **filePathToSave** : Path to save in file system
- **createDirIfNotExists** : Boolean to create the folder if the it doesn't exists. Default is `true`

### Get Pre-signed URL for private files

```js
client.getPresignedURL(path, expires);
```

- **path** : Path for the file to get the pre-signed URL
- **expires** : Time to expire the pre-signed URL (in seconds) (defaults to 900 seconds / 15 minutes);

## License

MIT © Bruno Orlandi
8 changes: 8 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ class SpacesClient {
return url.replace(/digitaloceanspaces/, 'cdn.digitaloceanspaces');
}

async getPresignedURL(path, expires = 900) {
return this.s3client.getSignedUrlPromise('getObject', {
Bucket: this.bucket,
Key: path,
Expires: expires,
});
}

async isFilePublic(filePath) {
const acl = await this.s3client.getObjectAcl({
Bucket: this.bucket,
Expand Down

0 comments on commit 3eeef95

Please sign in to comment.