-
Notifications
You must be signed in to change notification settings - Fork 266
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
File upload #48
Comments
Hi, just to let you know I will look at your example later this evening and pick this one up next! |
Thanks! |
Hi, I spent some time looking into this and I created an example in the POST >=>
choose [
route "/small-upload" >=> smallFileUploadHandler
route "/large-upload" >=> largeFileUploadHandler ] Then I implemented two handlers to deal with small and large file uploads: open System.Threading
open Microsoft.AspNetCore.Http.Features
let smallFileUploadHandler =
fun (ctx : HttpContext) ->
async {
return!
(match ctx.Request.HasFormContentType with
| false -> setStatusCode 400 >=> text "Bad request"
| true ->
ctx.Request.Form.Files
|> Seq.fold (fun acc file -> sprintf "%s\n%s" acc file.FileName) ""
|> text) ctx
}
let largeFileUploadHandler =
fun (ctx : HttpContext) ->
async {
let formFeature = ctx.Features.Get<IFormFeature>()
let! form = formFeature.ReadFormAsync CancellationToken.None |> Async.AwaitTask
return!
(form.Files
|> Seq.fold (fun acc file -> sprintf "%s\n%s" acc file.FileName) ""
|> text) ctx
} I used the built in features form ASP.NET Core. For small file uploads you can directly access the files by calling For large file uploads there is an existing It uses the What do you think of my two examples? Is there something you would like to add or extend from a Giraffe point of view? |
Hi, thanks for these examples. They are great! I had no idea that it could be this easy to process files. I don't think Giraffe itself needs any extension to work with files. |
It would be nice if we have some helper methods when uploading files.
Based on the aspnet core docs and this stackoverflow issue I came up with this but it the code isn't all that nice.
The text was updated successfully, but these errors were encountered: