import { type Oak } from "https://deno.land/x/oak_http_proxy@2.3.0/test/deps.ts";
const { FormDataReadOptions } = Oak;
Options which impact how the form data is decoded for a
FormDataReader
. All these options have sensible defaults for
most applications, but can be modified for different use cases. Many of these
options can have an impact on the stability of a server, especially if there
is someone attempting a denial of service attack on your server, so be
careful when changing the defaults.
Properties
The size of the buffer to read from the request body at a single time. This defaults to 1mb.
A mapping of custom media types that are supported, mapped to their extension when determining the extension for a file. The key should be an all lowercase media type with the value being the extension (without an initial period), to be used when decoding the file.
Example
Form data that is sent with content having a type of text/vdn.custom
will
be decoded and assigned a filename ending with .txt
:
import { Application } from "https://deno.land/x/oak/mod.ts";
const app = new Application();
app.use(async (ctx) => {
const body = ctx.request.body();
if (body.type === "form-data") {
const formatData = await body.value.read({
customContentTypes: {
"text/vnd.custom": "txt"
}
});
console.log(formData);
}
});
The maximum file size (in bytes) that can be handled. This defaults to
10MB when not specified. This is to try to avoid DOS attacks where
someone would continue to try to send a "file" continuously until a host
limit was reached crashing the server or the host. Also see maxSize
.
The maximum size (in bytes) of a file to hold in memory, and not write
to disk. This defaults to 0
, so that all multipart form files are
written to disk. When set to a positive integer, if the form data file is
smaller, it will be retained in memory and available in the .content
property of the FormDataFile
object. If the file exceeds the maxSize
it will be written to disk and the .filename
property will contain the
full path to the output file.
When writing form data files to disk, the output path. This will default
to a temporary path generated by Deno.makeTempDir()
.