UploadedFile.contentInMemory

For small files, cgi.d will buffer the uploaded file in memory, and make it directly accessible to you through the content member. I find this very convenient and somewhat efficient, since it can avoid hitting the disk entirely. (I often want to inspect and modify the file anyway!)

I find the file is very large, it is undesirable to eat that much memory just for a file buffer. In those cases, if you pass a large enough value for maxContentLength to the constructor so they are accepted, cgi.d will write the content to a temporary file that you can re-read later.

You can override this behavior by subclassing Cgi and overriding the protected handlePostChunk method. Note that the object is not initialized when you write that method - the http headers are available, but the cgi.post method is not. You may parse the file as it streams in using this method.

More...
struct UploadedFile
bool contentInMemory;

Detailed Description

Anyway, if the file is small enough to be in memory, contentInMemory will be set to true, and the content is available in the content member.

If not, contentInMemory will be set to false, and the content saved in a file, whose name will be available in the contentFilename member.

Tip: if you know you are always dealing with small files, and want the convenience of ignoring this member, construct Cgi with a small maxContentLength. Then, if a large file comes in, it simply throws an exception (and HTTP error response) instead of trying to handle it.

The default value of maxContentLength in the constructor is for small files.

Meta