Skip to content

Commit e9bf303

Browse files
committed
Follow similar colour schemese for upload and download pages
1 parent 4805511 commit e9bf303

File tree

2 files changed

+15
-26
lines changed

2 files changed

+15
-26
lines changed

frontend/src/components/DownloadPage.js

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const Title = styled.h2`
1919

2020
const Input = styled.input`
2121
width: 100%;
22+
box-sizing: border-box;
2223
padding: 12px;
2324
margin: 10px 0;
2425
border: 1px solid #ccc;
@@ -50,18 +51,10 @@ function DownloadPage() {
5051
const [fileName, setFileName] = useState("");
5152

5253
const handleDownload = async () => {
53-
if (!bucketName || !fileName) {
54-
alert("Please fill in all fields");
55-
return;
56-
}
57-
5854
try {
5955
const response = await axios.get("/file-transfer/download", {
60-
params: {
61-
bucketName,
62-
fileName,
63-
},
64-
responseType: "blob",
56+
params: { bucketName, fileName },
57+
responseType: "blob", // Download as binary stream
6558
});
6659

6760
const url = window.URL.createObjectURL(new Blob([response.data]));
@@ -71,9 +64,10 @@ function DownloadPage() {
7164
document.body.appendChild(link);
7265
link.click();
7366
link.remove();
67+
68+
alert(`File ${fileName} downloaded successfully from S3.`);
7469
} catch (error) {
75-
console.error("Error downloading file:", error);
76-
alert("Failed to download the file.");
70+
alert("Error downloading file from S3.");
7771
}
7872
};
7973

frontend/src/components/UploadPage.js

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const Title = styled.h2`
1919

2020
const Input = styled.input`
2121
width: 100%;
22+
box-sizing: border-box;
2223
padding: 12px;
2324
margin: 10px 0;
2425
border: 1px solid #ccc;
@@ -50,34 +51,28 @@ function UploadPage() {
5051
const [bucketName, setBucketName] = useState("");
5152
const [fileName, setFileName] = useState("");
5253

53-
const handleFileChange = (e) => {
54-
setFile(e.target.files[0]);
55-
};
56-
5754
const handleUpload = async () => {
58-
if (!file || !bucketName || !fileName) {
59-
alert("Please fill in all fields");
60-
return;
61-
}
62-
6355
const formData = new FormData();
6456
formData.append("file", file);
6557
formData.append("bucketName", bucketName);
6658
formData.append("fileName", fileName);
6759

6860
try {
69-
const response = await axios.post("/file-transfer/upload", formData);
70-
alert(response.data);
61+
await axios.post("/file-transfer/upload", formData);
62+
alert("File uploaded to S3 successfully!");
7163
} catch (error) {
72-
console.error("Error uploading file:", error);
73-
alert("Failed to upload the file.");
64+
alert("Error uploading file to S3.");
7465
}
7566
};
7667

7768
return (
7869
<Card>
7970
<Title>Upload to S3</Title>
80-
<Input type="file" onChange={handleFileChange} />
71+
<input
72+
type="file"
73+
onChange={(e) => setFile(e.target.files[0])}
74+
required
75+
/>
8176
<Input
8277
type="text"
8378
placeholder="Bucket Name"

0 commit comments

Comments
 (0)