FileInfo and StoredFile
FileInfo is an object's metadata, returned by head, list, search, and upload. StoredFile is a download - the same metadata plus File's name/type and the body accessors.
Every result that describes an object is a FileInfo. Only download adds a body, as a StoredFile.
interface FileInfo {
key: string;
size: number;
contentType: string;
etag?: string;
lastModified?: number; // ms since the epoch
metadata?: Record<string, string>;
}
interface StoredFile extends FileInfo {
// File-shaped aliases:
name: string; // = key
type: string; // = contentType
// The body:
arrayBuffer(): Promise<ArrayBuffer>;
text(): Promise<string>;
stream(): ReadableStream<Uint8Array>;
blob(): Promise<Blob>;
}
FileInfois whathead,list(andlistAll),search, anduploadreturn. It’s plain metadata with nothing lazy on it, so it’s safe to log, serialize, or cache. To read the bytes, calldownload(info.key).StoredFileis whatdownloadreturns. NativeFilecoversname,size,type, andlastModifiedbut not a storagekey,etag, or usermetadata, soStoredFilecarries both: theFileInfofields, plusnameandtypeso it can stand in where aFileis expected.
upload accepts a native File as input. A StoredFile’s body can be read once as a stream, or many times through text() / arrayBuffer() / blob() (call those before stream(), since they buffer the body for reuse).