shelf_multipart

Last updated:

0 purchases

shelf_multipart Image
shelf_multipart Images
Add to Cart

Description:

shelf multipart

shelf_multipart parses multipart and multipart/form-data requests for shelf handlers.
Handling multipart requests #
Multipart requests are represented by the MultipartRequest extension type. To
check whether a request is a multipart request, MultipartRequest.of or
the Request.multipart() extension method can be used:
import 'package:shelf_multipart/shelf_multipart.dart';
import 'package:shelf/shelf.dart';

Future<Response> myHandler(Request request) async {
if (request.multipart() case var multipart?) {
// Iterate over parts making up this request:
await for (final part in multipart.parts) {
// Headers are available through part.headers as a map:
final headers = part.headers;
// part implements the `Stream<List<int>>` interface which can be used to
// read data. You can also use `part.readBytes()` or `part.readString()`
}
} else {
return Response(401); // not a multipart request
}
}
copied to clipboard
Handling multipart/form-data #
Since form data is also sent as multipart requests, this package provides
methods to read form data as well:
if (request.formData() case var form?) {
// Read all form-data parameters into a single map:
final parameters = <String, String>{
await for (final formData in form.formData)
formData.name: await formData.part.readString(),
};
}
copied to clipboard

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Customer Reviews

There are no reviews.