Skip to main content

Storage Data Provider

File upload, download, and management.

Setup

<Refine
dataProvider={{
default: dataProvider(client),
storage: storageDataProvider(client),
}}
/>

List Files

const { result, query } = useList({
resource: "documents", // bucket name
dataProviderName: "storage",
});
// result.data → StorageObject[], result.total → number
// Each object: { id, path, size, mimetype, visibility, metadata, created_at, ... }

Get File URL

// Returns the download URL for the file
const { result, query } = useOne({
resource: "documents",
dataProviderName: "storage",
id: "uploads/document.pdf", // file path
});
// result.data → { id, path, url, ... } where url is the download URL

Upload Files

import type { StorageUploadVariables } from "@taruvi/refine-providers";

const { mutate, mutation } = useCreate<any, any, StorageUploadVariables>();

mutate({
resource: "documents",
dataProviderName: "storage",
values: {
files: [file1, file2],
paths: ["file1.pdf", "file2.pdf"], // optional, defaults to file.name
metadatas: [{ tag: "report" }, {}], // optional
},
});
// mutation.isLoading, mutation.isSuccess, mutation.isError
// onSuccess result.data → uploaded file metadata

Delete Files

const { mutate, mutation } = useDeleteMany();
mutate({
resource: "documents",
dataProviderName: "storage",
ids: ["path/to/file1.pdf", "path/to/file2.pdf"],
});
// mutation.isLoading, mutation.isSuccess

Filter Files

const { result, query } = useList({
resource: "documents",
dataProviderName: "storage",
filters: [
{ field: "mimetype_category", operator: "eq", value: "image" },
{ field: "size", operator: "lte", value: 5242880 },
{ field: "visibility", operator: "eq", value: "public" },
],
meta: { bucketName: "uploads" }, // override bucket name
});
// result.data → filtered StorageObject[], result.total → count