2020-03-12 10:26:31 +00:00
|
|
|
# [s3.js](https://git.rootprojects.org/root/s3.js) | a [Root](https://rootprojects.org) project
|
|
|
|
|
|
|
|
> Minimalist S3 client
|
|
|
|
|
2020-09-10 08:12:43 +00:00
|
|
|
A lightweight alternative to the s3 SDK that uses only @root/request and aws4.
|
2020-03-12 10:26:31 +00:00
|
|
|
|
2020-09-10 08:12:43 +00:00
|
|
|
- set()
|
|
|
|
- get()
|
|
|
|
- head()
|
|
|
|
- delete()
|
|
|
|
- sign()
|
|
|
|
|
|
|
|
Download a file from S3
|
|
|
|
|
|
|
|
```js
|
|
|
|
s3.get({
|
|
|
|
accessKeyId,
|
|
|
|
secretAccessKey,
|
|
|
|
region,
|
|
|
|
bucket,
|
|
|
|
prefix,
|
|
|
|
key
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
Upload a new file to S3
|
2020-03-12 10:26:31 +00:00
|
|
|
|
|
|
|
```js
|
|
|
|
s3.set({
|
|
|
|
accessKeyId,
|
|
|
|
secretAccessKey,
|
|
|
|
region,
|
|
|
|
bucket,
|
|
|
|
prefix,
|
|
|
|
key,
|
2020-03-17 01:58:31 +00:00
|
|
|
body,
|
|
|
|
size
|
2020-09-10 08:12:43 +00:00
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
Return signed URL without fetching.
|
|
|
|
|
|
|
|
```js
|
|
|
|
s3.sign({
|
|
|
|
method: 'get',
|
|
|
|
accessKeyId,
|
|
|
|
secretAccessKey,
|
|
|
|
region,
|
|
|
|
bucket,
|
|
|
|
prefix,
|
|
|
|
key
|
|
|
|
});
|
2020-03-12 10:26:31 +00:00
|
|
|
```
|
2020-03-17 01:58:31 +00:00
|
|
|
|
|
|
|
If the body is a stream then `size` must be set to `fs.statSync(filePath).size`, or the request will fail:
|
|
|
|
|
|
|
|
```
|
|
|
|
501
|
|
|
|
<Code>NotImplemented</Code><Message>A header you provided implies functionality that is not implemented</Message>
|
|
|
|
```
|