Search code examples
javascripthttpfile-uploadaxios

Is it possible to simulate a big file upload HTTP request without selecting a file in axios?


I have this requirement where I need to test file size limit and right now it's manual, because files are too big to be included in the CI/CD.

I wonder if it's possible for me to simulate a big file upload (using stupid random bytes for example) with Axios?

Has anyone ever done it?


Solution

  • You could try and create a fake "file" using the File() constructor.

    You can feed that with multiple different data types, it would perhaps make sense to start with string values in an array here - keeping the strings under the maximum allowed length, and adding as many as you need to reach your final required file size.

    Something like

    new File(["0123456789".repeat(10000000)], "name")
    

    "filled up" to (about) the desired size by adding more such strings to the array.