Skip to content

Commit

Permalink
added simple comfort message for error handling LOL
Browse files Browse the repository at this point in the history
  • Loading branch information
aesteri committed Oct 29, 2024
1 parent 7d3be88 commit c1cc45d
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/components/FileUpload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,35 +23,35 @@ const FileUpload: React.FC<FileUploadProps> = ({ uploadUrl }) => {
setSuccess(null)
if (selectedFiles.length > 0) {
try {
//Single file upload -- uploadUrl + /upload DOES NOT WORK
// SO --> Used bulk_upload instead for one file as well

// Bulk files upload
const formData = new FormData();
selectedFiles.forEach(file => {
formData.append('files', file);
formData.append('files', file);
});

try {
const response = await fetch(uploadUrl, {
method: 'POST',
body: formData,
method: 'POST',
body: formData,
});

if (!response.ok) {
if (response.status === 503) {
const errorMsg = await response.text();
setError(`Failed to upload: ${errorMsg} \nTry again in a few minutes!`);
} else {
const errorMsg = await response.text();
setError(`Failed to upload: ${errorMsg}`);
}
} else {
const result = await response.json();
setSuccess('File uploaded successfully!');
console.log('Upload successful:', result);
const result = await response.json();
setSuccess('File uploaded successfully!');
console.log('Upload successful:', result);
}
} catch (error) {
console.error('Error uploading files:', error);
setError('An error occurred during file upload.');
console.error('Error uploading files:', error);
setError('An error occurred during file upload.');
}


setSelectedFiles([]);
} catch (error) {
console.error('Upload failed:', error);
Expand Down

0 comments on commit c1cc45d

Please sign in to comment.