-
-
Notifications
You must be signed in to change notification settings - Fork 168
Expand file tree
/
Copy paths3helpers.ts
More file actions
28 lines (24 loc) · 683 Bytes
/
s3helpers.ts
File metadata and controls
28 lines (24 loc) · 683 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { S3Client } from "@aws-sdk/client-s3";
const hasAccessKeys = process.env.ACCESS_KEY && process.env.SECRET_KEY;
export const s3Client = new S3Client({
region: "eu-west-1",
...(hasAccessKeys
? {
credentials: {
accessKeyId: process.env.ACCESS_KEY || "",
secretAccessKey: process.env.SECRET_KEY || "",
},
}
: {}),
});
export const uploadFile = async (signedUrl: string, file: File) => {
const response = await fetch(signedUrl, {
body: file,
method: "PUT",
headers: {
"Content-Type": file.type,
},
});
const fileLocation = response.url.split("?")[0];
return { ...response, fileLocation };
};