Home > database >  Compress request body to send to PHP webserver
Compress request body to send to PHP webserver

Time:05-25

I have a Angular application which makes post request like the following:

  async syncDataWithMaster(): Promise<AxiosResponse<any> | void> {

....

      const jsonData = {
        lastSyncTimeStamp,
        deviceID,
        userUUID,
        lData,
        aData,
        aiData,
        fData,
        oData,
        caData,
      };

      axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded/json/gzip';
      axios.defaults.headers.post.Authorization = token;
      const url = this.endpoint   'syncData.php';
      return axios.post(url, jsonData, {
        onUploadProgress: progressEvent => {console.log('uploading')},
        onDownloadProgress: progressEvent => {console.log('downloading')}
      }).then((response) => {

        if (response.data.status == 'success') {
          return response;
        } else {
          throw new Error('Could not authenticate user');
        }
      });
    } catch (e) {
    }

    return;
  }

Usually this is fine for most of my user however some users have data up to 15-30mb. I am wondering if it possible to compress the data and send it to my PHP webserver which can then be decoded so that the upload is quicker?

CodePudding user response:

Maybe consider using a compression library (depending on the content of the body). It looks like fflate can do this.

  • Related