Web SDKv1.0.0

PDFExporter.uploadTo()

Upload the exported PDF (e.g. to an S3 presigned URL). Sends Content-Type: application/pdf unless headers overrides it. Needs export.
methodExportsince 1.0.0

Signature

uploadTo(url: string, options?: UploadOptions): Promise<Response>

Parameters

ParameterTypeDescription
urlstringWhere to send the file, e.g. an S3 presigned URL.
options?UploadOptionsEvery ExportOptions field, and the request's method (default 'PUT'), headers (Content-Type: application/pdf is sent unless these name one, in any case) and credentials (fetch's; same-origin by default, include for a cookie-authenticated endpoint on another origin). The signal cancels the upload too.

Returns

Promise<Response> The fetch Response. Does not reject on an HTTP error status — check response.ok.

Throws

  • NETWORK_ERROR when the request could not be sent at all (the address, the network, or a CORS refusal: the response must allow your origin).
  • ABORTED when signal aborts, during the export or the upload.
  • FEATURE_NOT_LICENSED when the license lacks export.
  • INVALID_ARGUMENT when pages is empty or names a page the document does not have, or when headers holds a name or value a request cannot carry.
  • INVALID_STATE when flatten is asked of a signed document without invalidateSignatures; from a viewer's exporter, when pending edits cannot be written or the document was reloaded under it.
  • PAGE_ERROR when a page cannot be loaded for flattening.
  • EXPORT_FAILED when the document cannot be written.
  • DOCUMENT_CLOSED after doc.close().

Example

TypeScript
const { url } = await (await fetch('/api/presign')).json();
const response = await viewer.createExporter().uploadTo(url, { method: 'PUT' });
if (!response.ok) showUploadFailed(response.status);

More in PDFExporter