Skip to content

Latest version not replacing url on resolve of image uploader #413

Description

@ShoaibShahid

the below function was working fine

function (blobInfo, success, failure) {
const xhr = new XMLHttpRequest();
xhr.open('POST', ${environment.SITE_BASE_URL}filemanager/filemanager/upload.php);
xhr.onload = function () {
if (xhr.status !== 200) {
failure('HTTP Error: ' + xhr.status);
return;
}
const json = JSON.parse(xhr.responseText);
if (!json?.files[0]?.url) {
failure('Invalid JSON: ' + xhr.responseText);
return;
}
success(json?.files[0]?.url);
};
xhr.onerror = function () {
failure('Image upload failed due to a XHR error');
};

    const formData = new FormData();
    formData.append('files[]', blobInfo.blob(), blobInfo.filename());
    formData.append('fldr', '');
    xhr.withCredentials = true;
    xhr.send(formData);
  }

In latest version I replace the above with below

(blobInfo, progress) => new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest();
xhr.open('POST', ${environment.SITE_BASE_URL}filemanager/filemanager/upload.php);

      xhr.onload = () => {
        if (xhr.status !== 200) {
          reject('HTTP Error: ' + xhr.status);
          return;
        }

        const json = JSON.parse(xhr.responseText);
        console.log(json);
        if (!json?.files[0]?.url) {
          reject('Invalid JSON: ' + xhr.responseText);
          return;
        }

        console.log(json?.files[0]?.url);
        resolve('https://apiss.kualiteestaging.com/files/mceclip1.png');
      };

      xhr.onerror = (error) => {
        console.log(error);
        reject('Image upload failed due to a XHR Transport error. Code: ' + xhr.status);
      };

      const formData = new FormData();
      formData.append('fldr', '');
      formData.append('files[]', blobInfo.blob(), blobInfo.filename());

      xhr.send(formData);
    })

but on resolving the url is not getting placed but it was happening with first version. Is I am doing something wrong or missing or its abug

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions