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

Commit

Permalink
refactor: removes authorization token from file upload
Browse files Browse the repository at this point in the history
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
  • Loading branch information
devraj committed Apr 20, 2023
1 parent 525a0bc commit 844279f
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/routers/auth/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ async({ request } : any) => {
}).catch((error) => {
console.log(error);
});
return redirect('/admin/users');
return redirect('/file');
};

function Login() {
Expand Down
63 changes: 61 additions & 2 deletions src/routers/upload/sample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,82 @@ import {
} from 'react-query';


import axios from "axios";


import {
getUploadUrl,
} from "api/file-uploads/file-uploads";

import {
FileUploadResponse
} from "api/models"


export const action = (queryClient: QueryClient) =>
async({ request } : any) => {
const formData = await request.formData();
console.log(formData);
return true;
};


function SampleUpload() {

const handleFileUpload = (e: any) => {
e.preventDefault();
const file = e.target[0].files[0];

console.log(file);

// File reader to read contents
const reader = new FileReader();
const fileContents = reader.readAsDataURL(file);

getUploadUrl({
fileName: file.name,
mimeType: file.type,
fileSize: file.size,
}).then((res:any) => {
console.log(res);
// axios({
// method: 'PUT',
// url: res.data.presignedUploadUrl,
// data: fileContents,
// headers: {
// 'Content-Type': file.type,
// }
// }).then((res) => {
// console.log(res);
// });

const requestOptions:any = {
method: 'PUT',
headers: {
'Content-Type': file.type,
},
body: file,
};
fetch(res.data.presignedUploadUrl, requestOptions).then(
(res) => {
console.log("here");
}
)

}).catch((err) => {
console.log(err);
});
}

return(
<div className="">
<h1>
Sample File Upload
</h1>
<Form method="post" id="upload-file">
<form onSubmit={handleFileUpload} method="post" id="upload-file">
<input type="file"></input>
<button type="submit">Upload</button>
</Form>
</form>
</div>
);
}
Expand Down

0 comments on commit 844279f

Please sign in to comment.