Namespaces

ovok.documents

Register uploads, update metadata, delete documents, and build download URLs.

  • Stable unknown
  • Release candidate since 0.4.49-rc.4
  • Development since 0.4.49-dev.517+4645a0a

Uploaded documents. Uploading is two steps: register the document with the API, then send the file to the pre-signed target it returns.

Upload a file

const doc = await ovok.documents.createUpload({
  fileName: 'report.pdf',
  contentType: 'application/pdf',
  isPublic: false,
});

if (doc.uploadOptions) {
  const form = new FormData();
  for (const [name, value] of Object.entries(doc.uploadOptions.fields)) form.append(name, value);
  form.append('file', file);
  await fetch(doc.uploadOptions.url, { method: 'POST', body: form });
}
  • createUpload only registers the document. The file goes straight to the storage URL; the SDK does not send it.
  • Put the file field last in the form, as pre-signed POST targets expect.
  • replaceUpload(documentId, body) registers a new file for an existing document. It takes the same fileName, contentType and isPublic.

List and change documents

const documents = await ovok.documents.list();
await ovok.documents.updateMetadata(documentId, metadata);
await ovok.documents.delete(documentId);
  • list takes an optional search query and returns the server's envelope.
  • Calls routes under document.

Build download URLs

const url = ovok.documents.downloadUrl(documentId, { width: 400 });
const publicUrl = ovok.documents.publicDownloadUrl(publicToken);
  • Both methods build a URL and make no request.
  • downloadUrl needs the bearer token: fetch it with the session's token, and it redirects to a signed URL. It cannot be used as an <img src>.
  • publicDownloadUrl needs no bearer, so it fits an image or media element. The token comes from a document registered with isPublic: true.
  • width, height and fit resize image downloads.

Reference

Last updated on

On this page