MinIO Client SDK for Haskell
Go to file
2017-03-15 15:26:48 +05:30
docs Add missing API docs (#29) 2017-03-14 13:22:20 +05:30
examples Add copyObject example. (#30) 2017-03-15 15:26:48 +05:30
src Add copyObject example. (#30) 2017-03-15 15:26:48 +05:30
test Add copyObject example. (#30) 2017-03-15 15:26:48 +05:30
.gitignore Initial commit 2017-02-13 02:19:43 -08:00
.travis.yml Rename putObjectFromSource as putObject 2017-02-18 16:40:30 +05:30
CONTRIBUTING.md Fix README.md wording and links. (#1) 2017-02-13 10:08:43 -08:00
LICENSE Initial commit 2017-02-13 02:19:43 -08:00
minio-hs.cabal Add copyObject API: (#5) 2017-02-23 14:04:08 +05:30
README.md Add FileUploader example to README (#6) 2017-03-02 11:48:04 +05:30
Setup.hs Add copyright header to all source files. (#20) 2017-03-02 16:01:59 +05:30
stack-ghc-8.0.1.yaml Add support for ghc 8 - build with "STACK_YAML=stack-ghc-8.0.1.yaml stack install" 2017-02-13 16:03:42 +05:30
stack.yaml GetObject s3api and fGetObject api 2017-02-13 16:03:42 +05:30

Minio Client SDK for Haskell Build StatusHackage

The Minio Haskell Client SDK provides simple APIs to access Minio and Amazon S3 compatible object storage server.

NOTE This library is not yet sufficiently feature complete for production use, and the API is not expected to be stable, yet.

Minimum Requirements

Installation

git clone https://github.com/minio/minio-hs.git

cd minio-hs/

stack install

Tests can be run with:


stack test

A section of the tests use the remote Minio Play server at https://play.minio.io:9000 by default. For library development, using this remote server maybe slow. To run the tests against a locally running Minio live server at http://localhost:9000, just set the environment MINIO_LOCAL to any value (and unset it to switch back to Play).

Documentation can be locally built with:


stack haddock

Quick-Start Example - File Uploader

FileUploader.hs

#!/usr/bin/env stack
-- stack --resolver lts-6.27 runghc --package minio-hs --package optparse-applicative --package filepath

{-# Language OverloadedStrings, ScopedTypeVariables #-}
import Network.Minio

import Control.Monad.Catch (catch)
import Control.Monad.IO.Class (liftIO)
import Options.Applicative
import Prelude
import System.FilePath.Posix
import Data.Text (pack)

-- | The following example uses minio's play server at
-- https://play.minio.io:9000.  The endpoint and associated
-- credentials are provided via the libary constant,
--
-- > minioPlayCI :: ConnectInfo
--

-- optparse-applicative package based command-line parsing.
fileNameOpts :: Parser FilePath
fileNameOpts = strOption
               (long "filename"
                <> metavar "FILENAME"
                <> help "Name of file to upload to AWS S3 or a Minio server")

cmdParser = info
            (helper <*> fileNameOpts)
            (fullDesc
             <> progDesc "FileUploader"
             <> header
             "FileUploader - a simple file-uploader program using minio-hs")


main :: IO ()
main = do
  let bucket = "my-bucket"

  -- Parse command line argument, namely --filename.
  filepath <- execParser cmdParser
  let object = pack $ takeBaseName filepath

  res <- runResourceT $ runMinio minioPlayCI $ do
    -- Make a bucket; catch bucket already exists exception if thrown.
    catch
      (makeBucket bucket Nothing)
      (\(_ :: MError) -> liftIO $ putStrLn "Bucket already exists, proceeding with upload file.")

    -- Upload filepath to bucket; object is derived from filepath.
    fPutObject bucket object filepath

  case res of
    Left e -> putStrLn $ "file upload failed due to " ++ (show e)
    Right () -> putStrLn "file upload succeeded."

Run fileuploader

./FileUploader.hs --filename "path/to/my/file"

Contribute

Contributors Guide