-
|
I have this code: .post("/message", async (ctx) => {
const body = await ctx.request.body({ type: "form-data" }).value.read({
outPath: `${Deno.cwd()}/static/private/attachment`,
});
console.log(body);
});which works great for most files. However sometimes the browser doesn't know what mime type to set for a given extension (i.e. custom extensions, or even some known extensions like .ttf/.otf), and when I send a file with no type to oak via edit: loving oak btw thanks to everyone for the great work |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
For security reasons, whenever the file is saved locally, it uses the provided content type to determine the extension. It is a lot better to trust browsers than end users when providing files. Trusting the uploaded file name and its extension is a problem, as they are easy to manipulate and may not be valid for the target operating/filesystem. Therefore the Adding an option to automatically do this doesn't make sense to me personally, as it is really important that the user of oak considers the implications of post processing uploaded files, in a way that makes the most sense for their use case. |
Beta Was this translation helpful? Give feedback.
For security reasons, whenever the file is saved locally, it uses the provided content type to determine the extension. It is a lot better to trust browsers than end users when providing files. Trusting the uploaded file name and its extension is a problem, as they are easy to manipulate and may not be valid for the target operating/filesystem.
Therefore the
FormDataFileprovides both the.filenameand.originalNameas part of the structure (as well as the provided.contentType), so if you "trust" what is uploaded, you can do post processing to reconcile it, using whatever logic you are comfortable with from a security and usability perspective.Adding an option to automatically do this d…