-
Notifications
You must be signed in to change notification settings - Fork 35
Parsing Multipart form
Ravi Teja Gudapati edited this page Jan 9, 2019
·
16 revisions
multipart/form-data
is usually used to upload forms with file fields. Jaguar has built-in support to parse HTTP requests with content type multipart/form-data
. bodyAsFormData
method on Context
object parses the body and returns the form-data as Map<String, FormField>
.
Future<Response> updateBook(Context ctx) async {
Map<String, FormField> body = await ctx.bodyAsFormData();
...
}
bodyAsFormData
can decode 3 types of form-data fields:
-
StringFormField
Field hasString
value
-
BinaryFileFormField
Field hasStream<List<int>>
value
-
TextFileFormField
Field hasStream<String>
value
Future<Redirect> upload(Context ctx) async {
final Map<String, FormField> formData = await ctx.bodyAsFormData();
final BinaryFileFormField pic = formData['pic'];
await pic.writeTo('bin/data/' + pic.filename);
return Redirect(Uri.parse("/"));
}
-
Upload files
Example showing how to leveragebodyAsFormData
andBinaryFormField
to upload files to the server.
In the next article, we will learn about Sessions and managing sessions in Jaguar.
Basics
- Route handler
- Path matching
- Path parameters
- Query parameters
- Serving static files
- Cookies
- Controller
- Parameter binding
- Hot reload
Serialization
Forms
Sessions
Authentication
- Basic authentication
- Form authentication
- JSON authentication
- Authorization
- OAuth
- MongoDb
- PostgreSQL
- MySQL
- Establish connection
- ORM
- Server sent events (SSE)
- Websockets
- systemd
- Docker
- AppEngine