- Developer home
- Embed editors
- Files from the person's computer
Files from the person's computer
Files from the person's computer
For a simple integration with no file store of its own, the token can let the person open a file from their computer in the editor. Two switches must both be on: the token's file.local, and your app's "Allow people to open files from their computer" in the developer console (off by default).
| Claim | Value |
|---|---|
file.local | true: no file yet. The token names no url or upload_id (and no name). |
file.accept | Optional: the kinds the person may open: any format in Supported formats, "code" for every code file and "ink" for .mrink (default: docx, xlsx, pptx and pdf). |
file.max_bytes | Optional: a size cap under your app's file size limit. |
file.replace | Optional, false by default: whether a second file may replace the document the key holds. |
- The editor shows a drop zone: the person drops a file anywhere on it, or chooses "Open from computer". Your page can also hand it a file with openFile().
- MR Office checks the file by its bytes as well as its name (an Office package's structure, a PDF's signature) under your app's size limit, then opens it in the same editor and Office engine as any other file. It becomes the document under the token's key; others given that key join it.
- A second file is refused (409 embed_document_has_file) unless the token has file.replace, and replaces the document only while no one else has it open. A view session waits for someone who can edit to open the file.
- Saving works as for any file. The first save always writes version 1 (you have no copy yet), and when everyone has left the document is saved once. The callback's document.source is "local" and document.name the person's file name; GET …/documents/{key}/content fetches it too.
- Files opened this way count in your usage (bytes in) and the audit trail (embed.document.local_open); at most 20 a minute per app by default.
// The token: a key and local: true, no url or upload_id.
const claims = {
iss: APP_ID, aud: "mroffice-embed", iat: now, exp: now + 600, jti: randomUUID(),
file: {
key: `acme-upload-${randomUUID()}`, // a fresh key: each person's own new document
local: true,
accept: ["docx", "xlsx", "pptx", "pdf"], // optional (all four by default)
max_bytes: 50 * 1024 * 1024, // optional, under your app's own limit
replace: false, // optional: may a second file replace the first?
},
mode: "edit",
user: { id: userId, name: userName },
};
// The page: the editor shows its own drop zone ("Open from computer")...
const editor = MROffice.open({
container: "#editor",
token,
onAwaitingFile: ({ accept, maxBytes }) => showMyOwnButton(),
onFileOpened: ({ name, size }) => console.log("opened", name, size),
onSave: (saved) => console.log("saved", saved.version, saved.downloadUrl),
});
// ...or hand it a file your page already has.
myInput.addEventListener("change", () => editor.openFile(myInput.files[0]));