III.2
Upload images and files from Creator
You need this: When form authors add logos, images or files to a form.
Creator raises onUploadFile when an author adds an image or a file. Upload it to your storage and put the returned URL into the definition: the same /api/files endpoint as in I.4, so there is no new server code. Creator saves automatically on this page.
This step on the Server Integration page
Source on GitHub
Commercial client licence: without SURVEYJS_LICENSE_KEY the component shows a licence banner
Try this
Code that just ran
These regions are read from the files that served this page, the same lines the Server Integration page shows.
shared/client/creator-uploads.js · sjs:III.2.client
View on GitHub
// Images and logos added in Creator: store them, keep only the URL in the definition
creator.onUploadFile.add(async (_, options) => {
const body = new FormData();
options.files.forEach(file => body.append("files[]", file)); // the I.4 endpoint; "files[]" for PHP
const [id] = await fetch("/api/files", { method: "POST", body }).then(r => r.json());
options.callback("success", `/api/files/${id}`); // I.4 returns ids: the definition keeps a URL
});
Definition: shared/definitions/creator-load-save.json