Implement necessary APIs
This commit is contained in:
parent
53915aad25
commit
5147163aa1
@ -7,8 +7,7 @@
|
||||
</head>
|
||||
<body>
|
||||
<script type="module">
|
||||
import { createClient, upload } from './dist/s3simp.js';
|
||||
const client = createClient('default');
|
||||
import s3simp from './dist/s3simp.js';
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
2127
package-lock.json
generated
2127
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -3,14 +3,15 @@
|
||||
"version": "1.0.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"build": "esbuild s3simp.js --bundle --minify --format=esm --outdir=dist",
|
||||
"build": "esbuild s3simp.js --bundle --minify --format=esm --define:global=window --outdir=dist",
|
||||
"build:dev": "esbuild s3simp.js --bundle --minify --sourcemap --define:global=window --format=esm --outdir=dist",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"description": "",
|
||||
"dependencies": {
|
||||
"@aws-sdk/client-s3": "^3.758.0"
|
||||
"aws-sdk": "^2.1692.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"esbuild": "0.25.1"
|
||||
|
30
s3simp.js
30
s3simp.js
@ -1,7 +1,14 @@
|
||||
import { S3Client, PutObjectCommand } from "@aws-sdk/client-s3";
|
||||
const S3 = require('aws-sdk/clients/s3.js');
|
||||
|
||||
export function createClient(region, maxAttempts) {
|
||||
return new S3Client({ region, maxAttempts });
|
||||
export function createClient({
|
||||
endpoint,
|
||||
accessKeyId,
|
||||
secretAccessKey,
|
||||
maxRetries = 3,
|
||||
signatureVersion = 'v4',
|
||||
region = 'auto',
|
||||
}) {
|
||||
return new S3({ endpoint, accessKeyId, secretAccessKey, maxRetries, signatureVersion, region });
|
||||
}
|
||||
|
||||
export async function upload({
|
||||
@ -9,17 +16,12 @@ export async function upload({
|
||||
Bucket,
|
||||
Key,
|
||||
Body,
|
||||
ContentMD5,
|
||||
ContentType,
|
||||
...rest
|
||||
}) {
|
||||
const command = new PutObjectCommand({
|
||||
Bucket,
|
||||
Key,
|
||||
Body,
|
||||
ContentMD5,
|
||||
ContentType,
|
||||
...rest
|
||||
});
|
||||
return await client.send(command);
|
||||
return await client.upload({ Bucket, Key, Body, ...rest }).promise();
|
||||
}
|
||||
|
||||
export default {
|
||||
createClient,
|
||||
upload,
|
||||
};
|
Loading…
Reference in New Issue
Block a user