adobe / helix-labs-website

Apache License 2.0
0 stars 6 forks source link

[Bulk Import] Convert to use multipart form-data #39

Closed arumsey closed 2 months ago

arumsey commented 2 months ago

The import service now requires multi part form data instead of JSON.

Use multipart/form-data content type to support upload of custom import.js https://github.com/adobe/spacecat-api-service/pull/487

The startButton click handler will need to be rewritten to create a form data object.

  const formData = new FormData();
  formData.append('urls', JSON.stringify(urlsArray));
  formData.append('options', JSON.stringify(options));
  formData.append('customHeaders', fields.headers.value);
  formData.append('importScript', fields.importScript.files[0]);

  const newJob = await service.startJob(formData);

The start service will then also need to be updated to accept a form data object.

      const headers = new Headers(this.#getAuthHeaders());
      headers.delete('Content-Type');
    const resp = await fetch(`${this.endpoint}${IMPORT_JOBS_PATH}`, {
      method: 'POST',
      headers,
      body: formData,
    });