33// MacroExpress / multer
44//
55// Created by Helge Heß on 30/05/16.
6- // Copyright © 2021 ZeeZide GmbH. All rights reserved.
6+ // Copyright © 2021-2025 ZeeZide GmbH. All rights reserved.
77//
88
99import MacroCore
@@ -15,18 +15,29 @@ import connect
1515 * Middleware to parse `multipart/form-data` payloads.
1616 *
1717 * E.g. files submitted using an HTML form like:
18- *
19- * <form action="/upload" method="POST" enctype="multipart/form-data">
20- * <input type="file" name="file" multiple="multiple" />
21- * <input type="submit" value="Upload" />
22- * </form>
18+ * ```html
19+ * <form action="/upload" method="POST" enctype="multipart/form-data">
20+ * <input type="file" name="file" multiple="multiple" />
21+ * <input type="submit" value="Upload" />
22+ * </form>
23+ * ```
2324 *
2425 * Roughly designed after the Node
2526 * [multer](https://github.com/expressjs/multer#readme)
2627 * package.
2728 */
2829public struct multer {
2930
31+ /**
32+ * A function that controls what files should be uploaded or skipped.
33+ *
34+ * This can be passed to a multer-init. The function gets the
35+ * `IncomingMessage`, the ``File`` and a callback that it **must** invoke to
36+ * continue multer processing.
37+ *
38+ * The filter can issue an error by passing on into the error parameter of the
39+ * callback. And it can pass in `true` or `false` to accept or reject a file.
40+ */
3041 public typealias FileFilter =
3142 ( IncomingMessage , File , @escaping ( Swift . Error ? , Bool ) -> Bool ) -> Void
3243
@@ -53,6 +64,20 @@ public struct multer {
5364 }
5465 #endif
5566
67+ /**
68+ * Create a new multer configuration.
69+ *
70+ * This accepts a ``MulterStorage``, ``Limits-swift.struct`` and
71+ * a ``FileFilter-swift.typealias``.
72+ * All of which are optional. The default storage is the ``MemoryStorage``.
73+ *
74+ * - Parameters:
75+ * - storage: Where to put uploaded files, defaults to ``MemoryStorage``
76+ * - limits: What ``Limits-swift.struct`` to apply, checks the
77+ * documentation for the defaults.
78+ * - fileFilter: A function that can filter what files should be uploaded,
79+ * defaults to "no filter", i.e. accept all files.
80+ */
5681 @inlinable
5782 public init ( storage : MulterStorage ? = nil ,
5883 limits : Limits = Limits ( ) ,
@@ -61,12 +86,18 @@ public struct multer {
6186 self . dest = nil
6287 self . fileFilter = fileFilter
6388 self . limits = limits
64- self . storage = storage ?? MemoryStorage ( )
89+ self . storage = storage ?? multer . memoryStorage ( )
6590 }
6691}
6792
6893public extension multer { // MARK: - Storage Factory
6994
95+ /**
96+ * Returns a multer storage that writes the file contents to the
97+ * ``File/buffer`` property of the ``File`` object, i.e. stores it in-memory.
98+ *
99+ * - Returns: A new ``MemoryStorage`` object.
100+ */
70101 @inlinable
71102 static func memoryStorage( ) -> MemoryStorage {
72103 return MemoryStorage ( )
0 commit comments