HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulehttp-client-0.7.19Haskell2010

Network.HTTP.Client.MultipartFormData

This module handles building multipart/form-data. Example usage:

{-# LANGUAGE OverloadedStrings #-}
import Network
import Network.HTTP.Client
import Network.HTTP.Client.MultipartFormData

import Data.Text.Encoding as TE

import Control.Monad

main = void $ withManager defaultManagerSettings $ \m -> do
    req1 <- parseRequest "http://random-cat-photo.net/cat.jpg"
    res <- httpLbs req1 m
    req2 <- parseRequest "http://example.org/~friedrich/blog/addPost.hs"
    flip httpLbs m =<<
        (formDataBody [partBS "title" "Bleaurgh"
                      ,partBS "text" $ TE.encodeUtf8 "矢田矢田矢田矢田矢田"
                      ,partFileSource "file1" "/home/friedrich/Photos/MyLittlePony.jpg"
                      ,partFileRequestBody "file2" "cat.jpg" $ RequestBodyLBS $ responseBody res]
            req2)
  • 2 types
  • 19 values

Part type

7 declarations
datadata PartM (m :: Type -> Type)
#

A single part of a multipart message.

Instances1Show
  • Show (PartM m)Defined in http-client-0.7.19 · Network.HTTP.Client.MultipartFormData

Constructing parts

7 declarations
valuepartFile
  1. :: Text

    Name of the corresponding <input>.

  2. -> FilePath

    The name of the local file to upload.

  3. -> Part
#

Make a Part from a file.

The entire file will reside in memory at once. If you want constant memory usage, use partFileSource.

The FilePath supplied will be used as the file name of the Part. If you do not want to reveal this name to the server, you must remove it prior to uploading.

The Part does not have a content type associated with it.

valuepartFileSource
  1. :: Text

    Name of the corresponding <input>.

  2. -> FilePath

    The name of the local file to upload.

  3. -> Part
#

Stream a Part from a file.

The FilePath supplied will be used as the file name of the Part. If you do not want to reveal this name to the server, you must remove it prior to uploading.

The Part does not have a content type associated with it.

valuepartFileRequestBody
  1. :: Applicative m
  2. => Text

    Name of the corresponding <input>.

  3. -> FilePath

    File name to supply to the server.

  4. -> RequestBody

    Data to upload.

  5. -> PartM m
#

Construct a Part from form name, filepath and a RequestBody

partFileRequestBody "who_calls" "caller.json" $ RequestBodyBS "{\"caller\":\"Jason J Jason\"}"
-- empty upload form
partFileRequestBody "file" mempty mempty

The Part does not have a content type associated with it.

valuepartFileRequestBodyM
  1. :: Text

    Name of the corresponding <input>.

  2. -> FilePath

    File name to supply to the server.

  3. -> m RequestBody

    Action that will supply data to upload.

  4. -> PartM m
#

Construct a Part from action returning the RequestBody

partFileRequestBodyM "cat_photo" "haskell-the-cat.jpg" $ do
    size <- fromInteger <$> withBinaryFile "haskell-the-cat.jpg" ReadMode hFileSize
    return $ RequestBodySource size $ CB.sourceFile "haskell-the-cat.jpg" $= CL.map fromByteString

The Part does not have a content type associated with it.

Headers

1 declaration

Building form data

2 declarations

Boundary

2 declarations

Misc

2 declarations