rCod
rCod

Reputation: 11

Asynchronous upload File with ng2-file-upload

I am using the ng2-file-upload module to upload large files.

The upload is done with a backend coded in java

Since the import of those files takes quite a long time, the http connection created between frontend and backend makes the nginx server exit with timeout.

How can I use the ng2-file-upload module in an asynchronous way?

So far i have instantiated the FileUploader this way, but the connection keeps open waiting for the response of the backend (tab Network of chrome)

this.uploader  = new FileUploader({ url: URL, 
  disableMultipart :true,
  formatDataFunctionIsAsync: true,
  formatDataFunction: async (item) => {
    return new Promise((resolve, reject) => {
      resolve({
        name: item._file.name,
        length: item._file.size,
        contentType: item._file.type,
        date: new Date()
      });
    });
  },
  itemAlias: 'CsvFile' });
}

Any help would be appreciated.

Thank you, RC

Upvotes: 1

Views: 703

Answers (1)

Scott L
Scott L

Reputation: 1

For those looking for the answer, this is a back-end issue. When receiving large files that will require some form of work done, you should spawn a new thread in your back-end to do that work while allowing the original thread to complete with a proper 200 response. By doing this, you allow the front-end to remain responsive while still processing your file. This is more a pattern than a language specific explanation, but should apply across the board.

Upvotes: 0

Related Questions