Showpad Upload Utilities
import { uploadToShowpadMyFiles, uploadPDFToShowpadMyFiles } from '@bbc/front-end-kit/js/showpad/utils/showpad-upload';
Utility functions for uploading files (especially PDFs) to Showpad's "My Files" section, with Showpad toast notifications for upload status.
uploadToShowpadMyFiles
Uploads a file to Showpad's My Files section and handles upload status notifications.
Tip
Showpad toast is automatically triggered on events of the emitter
Parameters
filename(string): The name to give the uploaded file.file(Blob): The file data to upload (must be a Blob).options(object): Configuration options for Showpad toast labels. All keys have defaults:uploadLabel(string, default'Uploading File to My Files'): Toast shown when upload starts.processingLabel(string, default'Processing File'): Toast shown while processing.successLabel(string, default'File uploaded successfully to My Files'): Toast shown on success.errorLabel(string, default'Upload failed, please try again later.'): Intended for the failure toast — currently unused (the'failed'event onlyconsole.logs the result, no toast is displayed).
Returns
Example
import { uploadToShowpadMyFiles } from '@bbc/front-end-kit/js/showpad/utils/showpad-upload';
const file = new Blob(['Hello, world!'], { type: 'text/plain' });
const emitter = await uploadToShowpadMyFiles('hello.txt', file);
uploadPDFToShowpadMyFiles
A shortcut for uploading a PDF file to Showpad My Files using the same options as uploadToShowpadMyFiles but with pdf-related status messages for the Showpad Toasts.
Parameters
filename(string): The name to give the uploaded file in Showpad.file(Blob): The PDF file to upload (must be a Blob).options(object, optional): Overrides for upload status toast labels. Defaults to PDF-specific messages ('Uploading PDF to My Files','Processing PDF','PDF uploaded successfully to My Files'). SeeuploadToShowpadMyFilesfor all available keys.
Returns
Example
import { uploadPDFToShowpadMyFiles } from '@bbc/front-end-kit/js/showpad/utils/showpad-upload';
const pdfFile = new Blob(['%PDF-1.4...'], { type: 'application/pdf' });
const emitter = await uploadPDFToShowpadMyFiles('document.pdf', pdfFile);