Skip to content

Instantly share code, notes, and snippets.

@manuscrypt
Last active April 27, 2019 21:11
Show Gist options
  • Save manuscrypt/2adf308bf809face1844d1f5ea298df2 to your computer and use it in GitHub Desktop.
Save manuscrypt/2adf308bf809face1844d1f5ea298df2 to your computer and use it in GitHub Desktop.
Elm: File Upload Request
doUploadFile : Maybe AuthToken -> String -> File -> (Result Http.Error UploadedFile -> msg) -> Cmd msg
doUploadFile mbToken name file msg =
Http.request
{ method = "PUT"
, headers = [Http.header "Authorization" <| "Bearer " ++ (tokenToString mbToken)]
, url = "api/upload"
, body =
Http.multipartBody
[ Http.stringPart "name" name
, Http.filePart "file" file
]
, expect = Http.expectJson msg uploadedFileDecoder
, timeout = Nothing
, tracker = Just (File.name file)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment