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
| Parameter | Type | Description |
|---|---|---|
| url | string | Where to send the file, e.g. an S3 presigned URL. |
| options? | UploadOptions | Every 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_ERRORwhen the request could not be sent at all (the address, the network, or a CORS refusal: the response must allow your origin).ABORTEDwhensignalaborts, during the export or the upload.FEATURE_NOT_LICENSEDwhen the license lacksexport.INVALID_ARGUMENTwhenpagesis empty or names a page the document does not have, or whenheadersholds a name or value a request cannot carry.INVALID_STATEwhenflattenis asked of a signed document withoutinvalidateSignatures; from a viewer's exporter, when pending edits cannot be written or the document was reloaded under it.PAGE_ERRORwhen a page cannot be loaded for flattening.EXPORT_FAILEDwhen the document cannot be written.DOCUMENT_CLOSEDafterdoc.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);