import { HttpClient } from '../http'; import { FileQueryParams, FileListResponse, FileResponse, FileUpdateData, BlobUploadOptions, BufferUploadOptions, MediaUploadResponse } from './types'; /** * A service class designed for interacting with the file management API in a Strapi application. * * It provides methods to fetch and retrieve files uploaded through the Strapi Media Library. * * Note that the Strapi upload plugin API uses a different response format than the content API, * returning file data as a flat array rather than the typical data/meta structure. */ export declare class FilesManager { private readonly _httpClient; /** * Creates an instance of FilesManager. * * @param httpClient - An instance of HttpClient to handle HTTP communication. * * @example * ```typescript * const httpClient = new HttpClient('http://localhost:1337/api'); * const filesManager = new FilesManager(httpClient); * ``` */ constructor(httpClient: HttpClient); /** * Creates an HTTP client with file-specific error interceptors. * * @param fileId - Optional file ID to include in error messages. * @returns A new HttpClient instance with file-specific error handling. */ private createFileHttpClient; /** * Retrieves a list of files based on optional query parameters. * * @param queryParams - Optional parameters to filter or sort the results. * @returns A promise that resolves to an array of file objects. * * @throws {FileForbiddenError} if the user does not have permission to list files. * @throws {HTTPError} if the HTTP client encounters connection issues, the server is unreachable, or authentication fails. * * @example * ```typescript * const filesManager = new FilesManager(httpClient); * * const files = await filesManager.find({ * filters: { mime: { $contains: 'image' } }, * sort: 'name:asc', * }); * * console.log(files); // Array of file objects * ``` */ find(queryParams?: FileQueryParams): Promise; /** * Retrieves a single file by its ID. * * @param fileId - The numeric identifier of the file to retrieve. * @returns A promise that resolves to a single file object. * * @throws {FileNotFoundError} if the file with the specified ID does not exist. * @throws {HTTPError} if the HTTP client encounters connection issues, the server is unreachable, or authentication fails. * * @example * ```typescript * const filesManager = new FilesManager(httpClient); * * const file = await filesManager.findOne(1); * * console.log(file); // File object with details * ``` */ findOne(fileId: number): Promise; /** * Updates metadata for an existing file. * * @param fileId - The numeric identifier of the file to update. * @param fileInfo - An object containing the fields to update. * @returns A promise that resolves to the updated file object. * * @throws {FileNotFoundError} if the file with the specified ID does not exist. * @throws {HTTPError} if the HTTP client encounters connection issues, the server is unreachable, or authentication fails. * * @example * ```typescript * const filesManager = new FilesManager(httpClient); * * const updatedFile = await filesManager.update(1, { * name: 'New file name', * alternativeText: 'Descriptive alt text for accessibility', * caption: 'A caption for the file' * }); * * console.log(updatedFile); // Updated file object * ``` */ update(fileId: number, fileInfo: FileUpdateData): Promise; /** * Deletes a file by its ID. * * @param fileId - The numeric identifier of the file to delete. * @returns A promise that resolves to the deleted file object. * * @throws {FileNotFoundError} if the file with the specified ID does not exist. * @throws {FileForbiddenError} if the user does not have permission to delete the file. * @throws {HTTPError} if the HTTP client encounters connection issues, the server is unreachable, or authentication fails. * * @example * ```typescript * const filesManager = new FilesManager(httpClient); * * await filesManager.delete(1); * console.log('File deleted successfully'); * ``` */ delete(fileId: number): Promise; /** * Uploads a new media file to the Strapi Media Library. * * @param file - The file to upload (Blob or Buffer). * @param options - Upload options. For Buffer uploads, filename and mimetype are required. * @returns A promise that resolves to the uploaded file information. * * @throws {FileForbiddenError} if the user does not have permission to upload files. * @throws {HTTPError} if the HTTP client encounters connection issues, the server is unreachable, or authentication fails. * * @example * ```typescript * const filesManager = new FilesManager(httpClient); * * // Upload with a File object (browser) * const fileInput = document.querySelector('input[type="file"]'); * const file = fileInput.files[0]; * const result = await filesManager.upload(file, { * fileInfo: { alternativeText: 'A user uploaded image' } * }); * * // Upload with a Blob * import { blobFrom } from 'node-fetch'; * const file = await blobFrom('./1.png', 'image/png'); * const result = await filesManager.upload(file, { * fileInfo: { alternativeText: 'An example image' } * }); * * // Upload with a Buffer (Node.js) - filename and mimetype are required * import fs from 'fs'; * const buffer = fs.readFileSync('./image.png'); * const result = await filesManager.upload(buffer, { * filename: 'image.png', * mimetype: 'image/png', * fileInfo: { alternativeText: 'An example image' } * }); * * console.log(result); // Upload response with file details * ``` */ upload(file: Blob, options?: BlobUploadOptions): Promise; upload(file: Buffer, options: BufferUploadOptions): Promise; private uploadBuffer; private uploadBlob; }