


export async function UploadImagesWithoutWait(postData,url){
   console.log(url,postData);
    return await UploadFormData(url,postData)
    .then((res)=>{
        console.log('test:',res);
        if(typeof res=='object' && res.error!=null){
            return false;
        }
        else if(res.includes('Success')){
            console.log('image uploaded');
            return true;
        }
        return false;
    })
    .catch((err)=>{
        console.log(err);
        return false;
    });
}

export async function UploadData2(url, indata) {

  return await fetch(url, {
    method: 'post',
    headers: {
      Accept: 'application/json',
      'Content-Type': 'application/json',
    },
    body: JSON.stringify(indata),
  })
    .then(response => {
      return response.json();
    })
    .then((res) => {
      return res;
    })
    .catch(err => {
      console.log('UploadData error', err);
      return { success: false, error: true, errorMsg: err };
    });
}

export async function UploadFormData(url, formData) {
  //  console.log(url,formData._parts);
  return await fetch(url, {
    method: 'post',
    headers: new Headers({ 'Content-Type': 'multipart/form-data', }),
    body: formData,
  })
    .then(response => {
      console.log('UploadData error3', response);
      return response.text();
    })
    .then((res) => {
      console.log('UploadData error1', res);
      return res;
    })
    .catch(err => {
      console.log('UploadData error2', err);
      return { success: false, error: err };
    });
}