@8ms/helpers 1.1.103 → 1.1.104
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/aws/s3/writeFile.d.ts
CHANGED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
declare type WriteUrlContents = {
|
|
2
|
+
bucket: string;
|
|
3
|
+
key: string;
|
|
4
|
+
url: string;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Download a file and write to S3.
|
|
8
|
+
*/
|
|
9
|
+
declare const writeUrlContents: ({ bucket, key, url }: WriteUrlContents) => Promise<void>;
|
|
10
|
+
export default writeUrlContents;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const get_1 = __importDefault(require("../../axios/get"));
|
|
7
|
+
const writeFile_1 = __importDefault(require("./writeFile"));
|
|
8
|
+
/**
|
|
9
|
+
* Download a file and write to S3.
|
|
10
|
+
*/
|
|
11
|
+
const writeUrlContents = async ({ bucket, key, url }) => {
|
|
12
|
+
return (0, get_1.default)({
|
|
13
|
+
config: {
|
|
14
|
+
responseType: "arraybuffer",
|
|
15
|
+
responseEncoding: "binary",
|
|
16
|
+
},
|
|
17
|
+
url,
|
|
18
|
+
})
|
|
19
|
+
.then(async (response) => {
|
|
20
|
+
await (0, writeFile_1.default)({
|
|
21
|
+
bucket,
|
|
22
|
+
data: response.data,
|
|
23
|
+
key,
|
|
24
|
+
ContentType: response.headers["content-type"],
|
|
25
|
+
ContentLength: response.headers["content-length"],
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
exports.default = writeUrlContents;
|