• Creates a pre-authenticated upload URL for a file in the specified file storage provider.

    This utility function simplifies the process of creating upload URLs by handling common tasks such as:

    • Setting the content type based on the file extension if not provided
    • Setting the file status to 'Uploading'
    • Managing the provider key if returned by the storage provider

    The function returns both the updated input object (with additional metadata) and the pre-authenticated upload URL that can be used by clients to upload the file directly to the storage provider.

    Type Parameters

    • TInput extends {
          ContentType?: string;
          ID: string;
          Name: string;
          ProviderID: string;
          ProviderKey?: string;
      }

    Parameters

    • providerEntity: FileStorageProviderEntity

      The file storage provider entity containing connection details

    • input: TInput

      The input object containing the file details: - ID: A unique identifier for the file - Name: The filename to use for storage - ProviderID: The ID of the storage provider to use - ContentType: (Optional) The MIME type of the file - ProviderKey: (Optional) Provider-specific key for the file

    Returns Promise<{
        UploadUrl: string;
        updatedInput: TInput & {
            ContentType: string;
            Status: string;
        };
    }>

    A promise that resolves to an object containing: - updatedInput: The input object with additional metadata (Status, ContentType, and possibly ProviderKey) - UploadUrl: The pre-authenticated URL for uploading the file

    Example

    // Create a pre-authenticated upload URL for a PDF document
    const fileStorageProvider = await entityMgr.FindById('FileStorageProvider', 'azure-main');
    const result = await createUploadUrl(
    fileStorageProvider,
    {
    ID: '123',
    Name: 'report.pdf',
    ProviderID: fileStorageProvider.ID
    }
    );

    // The content type is automatically determined from the file extension
    console.log(result.updatedInput.ContentType); // 'application/pdf'

    // The status is set to 'Uploading'
    console.log(result.updatedInput.Status); // 'Uploading'

    // The upload URL can be sent to the client for direct upload
    console.log(result.UploadUrl);