Skip to content

Commit 0ad1d7c

Browse files
Merge pull request #155 from microsoft/PSL-BUG-12797
fix: 0 byte/kb size file not allowed.
2 parents 474a9a5 + 1e04831 commit 0ad1d7c

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

App/backend-api/Microsoft.GS.DPS.Host/API/KernelMemory/KernelMemory.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,17 @@ DPS.API.KernelMemory kernelMemory
4949
Summary = $"{fileExtension} file is Unsupported file type" });
5050
}
5151

52+
// Checking File Size: O byte/kb file not allowed
53+
if (file == null || file.Length == 0)
54+
{
55+
return Results.BadRequest(new DocumentImportedResult()
56+
{
57+
DocumentId = string.Empty,
58+
MimeType = contentType,
59+
Summary = "The file is empty and cannot be uploaded. Please select a valid file."
60+
});
61+
}
62+
5263
var result = await kernelMemory.ImportDocument(fileStream, file.FileName, contentType);
5364

5465
//Return HTTP 202 with Location Header

App/frontend-app/src/components/uploadButton/uploadButton.tsx

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { getFileTypeIconProps } from "@fluentui/react-file-type-icons";
2424
const UploadDocumentsDialog = () => {
2525
const [isOpen, setIsOpen] = useState(false);
2626
const [uploadingFiles, setUploadingFiles] = useState<
27-
{ name: string; progress: number; status: string }[]
27+
{ name: string; progress: number; status: string; errorMsg:string }[]
2828
>([]);
2929
const [isUploading, setIsUploading] = useState(false);
3030

@@ -35,6 +35,7 @@ const UploadDocumentsDialog = () => {
3535
name: file.name,
3636
progress: 0,
3737
status: "uploading",
38+
errorMsg : ""
3839
}));
3940
setUploadingFiles((prev) => [...prev, ...newFiles]);
4041

@@ -52,18 +53,19 @@ const UploadDocumentsDialog = () => {
5253
setUploadingFiles((prev) =>
5354
prev.map((f, index) =>
5455
index === prev.length - acceptedFiles.length + i
55-
? { ...f, progress: 100, status: "success" }
56+
? { ...f, progress: 100, status: "success", errorMsg: "" }
5657
: f
5758
)
5859
);
59-
} catch (error) {
60-
console.error("Error uploading file:", error);
60+
} catch (error:any) {
61+
const errorMessage = error.message.replace(/^Error:\s*/, ""); // Remove "Error: " prefix
62+
const parsedError = JSON.parse(errorMessage);
6163

6264
// Update file status to error
6365
setUploadingFiles((prev) =>
6466
prev.map((f, index) =>
6567
index === prev.length - acceptedFiles.length + i
66-
? { ...f, progress: 100, status: "error" }
68+
? { ...f, progress: 100, status: "error", errorMsg: parsedError.summary}
6769
: f
6870
)
6971
);
@@ -188,13 +190,17 @@ const UploadDocumentsDialog = () => {
188190
)}
189191
</div>
190192
<ProgressBar value={file.progress} />
191-
<span>
193+
<span
194+
style={{
195+
color: file.status === "error" ? "red" : "inherit", // Apply red color only for error messages
196+
}}>
192197
{file.status === "uploading"
193198
? "Uploading..."
194199
: file.status === "success"
195200
? "Upload complete"
196-
: "Upload failed"}
201+
: file.errorMsg}
197202
</span>
203+
<span>{}</span>
198204
</div>
199205
))}
200206
</DialogContent>

0 commit comments

Comments
 (0)