英文:
Is it possible to simulate a big file upload HTTP request without selecting a file in axios?
问题
我有这个需求,需要测试文件大小限制,但目前是手动操作,因为文件太大,无法包含在CI/CD中。
我想知道是否有可能使用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?
答案1
得分: 2
你可以尝试使用File()
构造函数来创建一个伪造的“文件”。
您可以将多种不同的数据类型传递给它,也许最好从数组中的字符串值开始 - 保持字符串长度不超过允许的最大长度,并根据需要添加足够多的字符串以达到所需的最终文件大小。
类似于
new File(["0123456789".repeat(10000000)], "name")
通过向数组中添加更多这样的字符串来“填满”(大约)所需的大小。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论