Uploading files
Deriving the datasource ID
const dataSourceId = dsProjectFiles.getDataSourceId();Uploading files with useData
useDataimport { useData, useDragAndDropUpload } from "@olenbetong/appframe-react";
function ProjectFiles({ projectId }: { projectId: number }) {
let files = useData(dsProjectFiles, `[ProjectID] = ${projectId}`);
let { upload, status } = useDragAndDropUpload({
dataObject: dsProjectFiles,
fields: { ProjectID: projectId },
validateFile(item) {
return item.type.startsWith("image/");
},
});
function handleFileChanged(e: React.ChangeEvent<HTMLInputElement>) {
let file = e.target.files?.[0];
if (file) upload([file]);
}
return (
<>
<input type="file" onChange={handleFileChanged} />
<ul>
{files.map((row) => (
<li key={row.ID}>{row.FileName}</li>
))}
</ul>
{status.map((s) => (
!s.complete && (
<progress key={s.index} value={s.progress.loaded} max={s.progress.total} />
)
))}
</>
);
}Binding to the current row
Deleting files
Security and validation
Last updated
Was this helpful?