SurveyJS PHP Backend Integration with Laravel /

Upload Files

Upload Files

Use when: Form authors need to add logos, images, or other files.

Read this step in the docs

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. Data shows the JSON schema's logo as /api/files/<id>: a URL, not Base64.
  3. The logo in the Designer loads from GET /api/files/<id>.

Commercial client licence: without SURVEYJS_LICENSE_KEY the component shows a licence banner.

    No requests yet.

      What the server stored

      Source on GitHub Definition: shared/definitions/creator-load-save.json Commercial client licence: without SURVEYJS_LICENSE_KEY the component shows a licence banner

      Client · shared/client/creator-uploads.js · sjs:creator-uploads.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));   // POST /api/files; "files[]" for PHP
        const [id] = await fetch("/api/files", { method: "POST", body }).then(r => r.json());
        options.callback("success", `/api/files/${id}`);                // the endpoint returns ids: the definition keeps a URL
      });