Skip to content

Instantly share code, notes, and snippets.

@woss
Created April 28, 2023 11:39
Show Gist options
  • Select an option

  • Save woss/c582a067b3b06e8f99d9b37f2468f64f to your computer and use it in GitHub Desktop.

Select an option

Save woss/c582a067b3b06e8f99d9b37f2468f64f to your computer and use it in GitHub Desktop.

Revisions

  1. woss created this gist Apr 28, 2023.
    21 changes: 21 additions & 0 deletions stream-dl-to-upstream-using-axios.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    import axios from "axios";
    import FormData from "form-data";

    // create DL stream
    const dl = await axios.get('url.tar', {
    responseType: "stream",
    });

    // create multipart
    const formData = new FormData();
    formData.append('file', dl.data);

    // directly proxy the stream to the upstream
    const up = await axios({
    method: 'POST',
    url: `upstream-url/api/post/add`,
    data: formData,
    maxContentLength: Infinity
    });

    console.log(up.data)