Horje
node js url download Code Example
node js url download
export async function downloadFile(fileUrl: string, outputLocationPath: string) {
  const writer = createWriteStream(outputLocationPath);

  return Axios({
    method: 'get',
    url: fileUrl,
    responseType: 'stream',
  }).then(response => {

    //ensure that the user can call `then()` only when the file has
    //been downloaded entirely.

    return new Promise((resolve, reject) => {
      response.data.pipe(writer);
      let error = null;
      writer.on('error', err => {
        error = err;
        writer.close();
        reject(err);
      });
      writer.on('close', () => {
        if (!error) {
          resolve(true);
        }
        //no need to call the reject here, as it will have been called in the
        //'error' stream;
      });
    });
  });
}




Javascript

Related
gps nodejs Code Example gps nodejs Code Example
how does URL.createObjectURl differ from fileReader Code Example how does URL.createObjectURl differ from fileReader Code Example
Checking if the first letter of the string is uppercase Code Example Checking if the first letter of the string is uppercase Code Example
js object to c# object Code Example js object to c# object Code Example
Create calculator calling different operators with functions in javascript Code Example Create calculator calling different operators with functions in javascript Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
9