-
-
Notifications
You must be signed in to change notification settings - Fork 20
Open
Labels
enhancementNew feature or requestNew feature or requestpackage: @hattip/multipartIssue related to ./packages/base/multipartIssue related to ./packages/base/multipart
Description
Assume a multipart form with the following fields:
- csrf
- projectId
- files
With the current @hattip/multipart
parsing you have no way to check the csrf, before processing the files. You also have no way to access the projectId in the handleFile
function, which is tedious when you wanna include that projectId in the resulting file path. Currently the only way is to either provide csrf and projectId via headers or query parameters, or to store the files in a temporary directory.
Idea: add options to control the order of the parsing and to hook into fields. Also add the already processed fields as a second parameter of handleFile
.
let projectId = '';
const formData = await parseMultipartFormData(request, {
// not all fields have to be in the order, missing fields will be processed at the end
order: ["csrf", "projectId"],
async handleField(name, value) {
if (name === 'csrf' && value !== PROPER_CSRF) {
throw new Error("Access denied");
}
if (name === 'projectId') {
projectId = value;
}
return value;
},
async handleFile(info, fields) {
// access projectId via "fields", or via the "projectId" variable from above
...upload things
}
})
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requestpackage: @hattip/multipartIssue related to ./packages/base/multipartIssue related to ./packages/base/multipart