Member Junction
    Preparing search index...

    Variable createUploadUrlConst

    createUploadUrl: <
        TInput extends
            {
                ContentType?: string;
                ID: string;
                Name: string;
                ProviderID: string;
                ProviderKey?: string;
            },
    >(
        providerEntity: MJFileStorageProviderEntity,
        input: TInput,
        userContext?: UserContextOptions,
    ) => Promise<
        {
            updatedInput: TInput & { ContentType: string; Status: string };
            UploadUrl: string;
        },
    > = CreateUploadUrl

    Type Declaration

      • <
            TInput extends
                {
                    ContentType?: string;
                    ID: string;
                    Name: string;
                    ProviderID: string;
                    ProviderKey?: string;
                },
        >(
            providerEntity: MJFileStorageProviderEntity,
            input: TInput,
            userContext?: UserContextOptions,
        ): Promise<
            {
                updatedInput: TInput & { ContentType: string; Status: string };
                UploadUrl: string;
            },
        >
      • 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: MJFileStorageProviderEntity

          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

        • OptionaluserContext: UserContextOptions

          Optional user context for OAuth providers (required if provider.RequiresOAuth is true)

        Returns Promise<
            {
                updatedInput: TInput & { ContentType: string; Status: string };
                UploadUrl: 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

        // 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
        },
        { userID: currentUser.ID, contextUser } // Required for OAuth providers
        );

        // 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);

    Use CreateUploadUrl.