SurveyJS Server Integration · PHP / Laravel III.2 · Upload images and files from Creator
You work in a private copy of the demo database, kept until it has been unused for 24 hours.

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

  1. In the Designer, click the logo area at the top of the form (Add logo... next to the title) and pick an image. Requests shows POST /api/files, then PUT /api/forms/support.
  2. "What the server stored" shows the definition's logo as /api/files/<id>: a URL, not base64.
  3. The logo in the Designer loads from GET /api/files/<id>, which checks access like any private file.

Code that just ran

These regions are read from the files that served this page, the same lines the Server Integration page shows.

Client · 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