Skip to content
This repository was archived by the owner on Oct 26, 2023. It is now read-only.

Commit 844279f

Browse files
committed
refactor: removes authorization token from file upload
initially it was the non-ssl endpoint causing the preflight call to fail and subsequently turns out that the axios global configuration adding the authorization header to the s3 file upload causing to be treated as a bad request. we should develop a standad s3 bucket policy as part of REFS #19 for use against projects
1 parent 525a0bc commit 844279f

File tree

2 files changed

+62
-3
lines changed

2 files changed

+62
-3
lines changed

src/routers/auth/login.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ async({ request } : any) => {
2020
}).catch((error) => {
2121
console.log(error);
2222
});
23-
return redirect('/admin/users');
23+
return redirect('/file');
2424
};
2525

2626
function Login() {

src/routers/upload/sample.tsx

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,82 @@ import {
77
} from 'react-query';
88

99

10+
import axios from "axios";
11+
12+
13+
import {
14+
getUploadUrl,
15+
} from "api/file-uploads/file-uploads";
16+
17+
import {
18+
FileUploadResponse
19+
} from "api/models"
20+
21+
1022
export const action = (queryClient: QueryClient) =>
1123
async({ request } : any) => {
1224
const formData = await request.formData();
1325
console.log(formData);
26+
return true;
1427
};
1528

1629

1730
function SampleUpload() {
31+
32+
const handleFileUpload = (e: any) => {
33+
e.preventDefault();
34+
const file = e.target[0].files[0];
35+
36+
console.log(file);
37+
38+
// File reader to read contents
39+
const reader = new FileReader();
40+
const fileContents = reader.readAsDataURL(file);
41+
42+
getUploadUrl({
43+
fileName: file.name,
44+
mimeType: file.type,
45+
fileSize: file.size,
46+
}).then((res:any) => {
47+
console.log(res);
48+
// axios({
49+
// method: 'PUT',
50+
// url: res.data.presignedUploadUrl,
51+
// data: fileContents,
52+
// headers: {
53+
// 'Content-Type': file.type,
54+
// }
55+
// }).then((res) => {
56+
// console.log(res);
57+
// });
58+
59+
const requestOptions:any = {
60+
method: 'PUT',
61+
headers: {
62+
'Content-Type': file.type,
63+
},
64+
body: file,
65+
};
66+
fetch(res.data.presignedUploadUrl, requestOptions).then(
67+
(res) => {
68+
console.log("here");
69+
}
70+
)
71+
72+
}).catch((err) => {
73+
console.log(err);
74+
});
75+
}
76+
1877
return(
1978
<div className="">
2079
<h1>
2180
Sample File Upload
2281
</h1>
23-
<Form method="post" id="upload-file">
82+
<form onSubmit={handleFileUpload} method="post" id="upload-file">
2483
<input type="file"></input>
2584
<button type="submit">Upload</button>
26-
</Form>
85+
</form>
2786
</div>
2887
);
2988
}

0 commit comments

Comments
 (0)