optimistic-gold
optimistic-gold10mo ago

upload file using antD

I need to upload a file with specific format. Exist any hook to do it?
2 Replies
kapa.ai
kapa.ai10mo ago
Hi @Sebastos. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Yes, Refine provides a way to upload files using Ant Design. You can use the useImport hook to import data from a CSV file. This hook is compatible with Ant Design's <Upload> and <Button> components. Here is a basic usage example of useImport hook:
import { ImportButton, useImport } from "@refinedev/antd";

export const PostList: React.FC = () => {
const importProps = useImport();

return <ImportButton {...importProps}>Import</ImportButton>;
};
import { ImportButton, useImport } from "@refinedev/antd";

export const PostList: React.FC = () => {
const importProps = useImport();

return <ImportButton {...importProps}>Import</ImportButton>;
};
You can also use the uploadProps property for more customization:
import { useImport } from "@refinedev/antd";
import { Upload, Button } from "antd";

export const PostList: React.FC = () => {
const { buttonProps, uploadProps } = useImport();

return (
<Upload {...uploadProps}>
<Button {...buttonProps}>Import</Button>
</Upload>
);
};
import { useImport } from "@refinedev/antd";
import { Upload, Button } from "antd";

export const PostList: React.FC = () => {
const { buttonProps, uploadProps } = useImport();

return (
<Upload {...uploadProps}>
<Button {...buttonProps}>Import</Button>
</Upload>
);
};
The uploadProps property includes several properties such as onChange to handle the file upload, beforeUpload to prevent the file from being uploaded automatically, showUploadList to hide the upload list, and accept to accept only CSV files. For more information, you can refer to the useImport documentation (https://refine.dev/docs/ui-integrations/ant-design/hooks/use-import) and uploadProps documentation (https://refine.dev/docs/ui-integrations/ant-design/hooks/use-import#uploadprops). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai10mo ago
<@689846866837373077> kapa.ai is still learning and improving, please let us know how it did by reacting below

Did you find this page helpful?