Skip to content

uploadVariantFile(productId: number, file: File): Promise<TFileUploadResponse | null>

The uploadVariantFile method allows to upload a file as a part of a file control.

Input parameters

productId

productId is a mandatory parameter of the number type that represents the id of a product for which the file should be uploaded.

file

file is a mandatory parameter of the File type that represents the object of file options.

Returned value

A returned value has a type of Promise<TFileUploadResponse | null>. If a file uploads successfully then it returns a TFileUploadResponse. If it doesn't then it returns null.

Example

In this example we make a basketUpdaterApi call to upload a variant file associated with some basket item.

useStorefront(async ({ eventBus, getApi }) => {
    eventBus.on('basket.initialized', async () => {
        const basketUpdaterApi = await getApi('basketUpdaterApi');

        const exampleFile = new File([], 'test.jpg');

        const currentBasket = basketUpdaterApi.uploadVariantFile(12, exampleFile);
    });
});

Basket Updater API methods reference