how to solve upload multipe files cached in temporary folder
Published Date: 2024-11-07 11:20:30Z
0x00 Description
I am reported that when him upload multipe files with my Simserver
, it will be cached in temporary folder. Such as C
Drives in Windows.
0x01 Getting Started
I found these issues:
- why not move the temp file rather than copy the same file when upload a large file?
- Streaming POST request instead of using temp file
And I think it's a problem with golang net/http
package. So I try to use .NET 8 to avoid this problem. Unfortunately, I found that .NET 8 has the same problem.
I found it is not a simple problem. I have to find a solution to solve this problem.
0x02 First: Look At The Http Protocol
This is some base knowledge about http protocol.
After I read these, I found that the problem is backend default parse the multipart/form-data
request body with read fully.
So, there is a problem that the backend can't read the request body fully in memory and the backend will cache the request body in temporary folder.
0x03 Solution
Base on the above knowledge, we could solve this problem by upload the file with streaming to avoid using multipart/form-data
.
There are 2 ways to upload the file with streaming:
- Backend directly read and write(handle) the request body with streaming.
- Pros:
- Easy to implement.
- Cons:
- It can't upload multipe files.
- Pros:
- Define a new binary protocol for upload the file and parse the binary protocol with backend.
- Pros:
- It can do more features in need.
- Cons:
- It is a little complex.
- Pros:
0x04 Extra
Before I writing this article, I have solve this problem in Simserver
commit with the 1st way. But I think it's not a good solution to my origin need.
At last, I think I need the easiest way to solve this problem.