Skip to content

Commit

Permalink
File uploader beta upload restrictions example (#5338)
Browse files Browse the repository at this point in the history
  • Loading branch information
epfeiffe authored Jun 28, 2024
1 parent 9f7f6b6 commit f9b49b6
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
2 changes: 0 additions & 2 deletions documentation-site/examples/file-uploader-beta/basic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ export default function Example() {
return (
<FileUploaderBeta
fileRows={fileRows}
itemPreview
maxFiles={5}
processFileOnDrop={processFileOnDrop}
setFileRows={setFileRows}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import * as React from "react";
import { FileUploaderBeta, type FileRow } from "baseui/file-uploader-beta";

export default function Example() {
const [fileRows, setFileRows] = React.useState<Array<FileRow>>([]);

const processFileOnDrop = (
file: File,
): Promise<{ errorMessage: string | null; fileInfo?: any }> => {
return new Promise((resolve) => {
// Fake an upload process for 2 seconds
// For a real-world scenario, replace this with application upload logic
setTimeout(() => {
let fileInfo = {
file,
objectID: "1234",
uploadID: "1234",
uploadStatus: "error",
};
resolve({ errorMessage: "Custom user error", fileInfo });
}, 2000);
});
};

return (
<FileUploaderBeta
accept={["image/png", "application/pdf"]}
fileRows={fileRows}
hint={
'Try uploading files that break these conditions: 1. accept set to ["image/png", "application/pdf"], 2. minSize set to 20000 bytes (20 KB), 3. maxSize set to 100000 bytes (100 KB), 4. maxFiles set to 3'
}
maxFiles={3}
maxSize={100000}
minSize={20000}
processFileOnDrop={processFileOnDrop}
setFileRows={setFileRows}
/>
);
}
8 changes: 8 additions & 0 deletions documentation-site/pages/components/file-uploader-beta.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Layout from "../../components/layout";
import Exports from "../../components/exports";

import FileUploaderBetaBasic from "examples/file-uploader-beta/basic.tsx";
import FileUploaderBetaUploadRestrictions from "examples/file-uploader-beta/upload-restrictions.tsx";

import * as FileUploaderBetaExports from "baseui/file-uploader-beta";

Expand Down Expand Up @@ -44,6 +45,13 @@ To learn more, read the corresponding [OWASP article on file uploads](https://ww
<FileUploaderBetaBasic />
</Example>

<Example
title="Upload restrictions"
path="file-uploader-beta/upload-restrictions.tsx"
>
<FileUploaderBetaUploadRestrictions />
</Example>

<Exports
component={FileUploaderBetaExports}
title="File uploader beta exports"
Expand Down

0 comments on commit f9b49b6

Please sign in to comment.