Ir al contenido

Storage & File Uploads

Esta página aún no está disponible en tu idioma.

Rebase provides built-in file upload support in collection forms:

  • Drag-and-drop file upload fields
  • Image previews in forms and table cells
  • Multiple file uploads via array properties
  • MIME type filtering and size limits
  • Custom filenames via callback functions

To add file uploads to a collection, use the storage config on a string property:

properties: {
image: {
type: "string",
name: "Product Image",
storage: {
storagePath: "products", // Subdirectory in storage
acceptedFiles: ["image/*"], // MIME type filter
maxSize: 5 * 1024 * 1024, // 5MB max
fileName: (context) => { // Custom filename
return context.entityId + "_" + context.file.name;
}
}
}
}
PropertyTypeDescription
storagePathstringSubdirectory within the storage backend
acceptedFilesstring[]Allowed MIME types (e.g., ["image/*"], ["application/pdf"])
maxSizenumberMaximum file size in bytes
fileNamefunctionCustom filename generator
metadataobjectAdditional metadata to store with the file
storeUrlbooleanStore the full URL instead of the relative path

Wrap the storage property in an array for multiple file uploads:

photos: {
type: "array",
name: "Photos",
of: {
type: "string",
storage: {
storagePath: "photos",
acceptedFiles: ["image/*"]
}
}
}

Upload non-image files like PDFs:

documents: {
type: "array",
name: "Documents",
of: {
type: "string",
storage: {
storagePath: "documents",
acceptedFiles: ["application/pdf", "image/*"]
}
}
}

For programmatic file operations outside of collection forms:

import { useStorageSource } from "@rebasepro/core";
const storageSource = useStorageSource();
// Upload a file
const result = await storageSource.uploadFile({
file,
fileName: "my-file.pdf",
path: "documents"
});
// Get download URL
const url = await storageSource.getDownloadURL(result.path);