1# MinIO Haskell Client SDK for Amazon S3 Compatible Cloud Storage [](https://github.com/minio/minio-hs/actions/workflows/ci.yml)[](https://hackage.haskell.org/package/minio-hs)[](https://slack.min.io)
3The MinIO Haskell Client SDK provides simple APIs to access [MinIO](https://min.io) and any Amazon S3 compatible object storage.
5This guide assumes that you have a working [Haskell development environment](https://www.haskell.org/downloads/).
11Simply add `minio-hs` to your project's `.cabal` dependencies section or if you are using hpack, to your `package.yaml` file as usual.
13### Try it out in a [REPL](https://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop)
15#### For a cabal based environment
17Download the library source and change to the extracted directory:
21$ cd minio-hs-1.6.0/ # directory name could be different
24Then load the `ghci` REPL environment with the library and browse the available APIs:
28ghci> :browse Network.Minio
31#### For a stack based environment
33From your home folder or any non-haskell project directory, just run:
39Then start an interpreter session and browse the available APIs with:
43> :browse Network.Minio
48The [examples](https://github.com/minio/minio-hs/tree/master/examples) folder contains many examples that you can try out and use to learn and to help with developing your own projects.
50### Quick-Start Example - File Uploader
52This example program connects to a MinIO object storage server, makes a bucket on the server and then uploads a file to the bucket.
54We will use the MinIO server running at https://play.min.io in this example. Feel free to use this service for testing and development. Access credentials are present in the library and are open to the public.
59-- stack --resolver lts-14.11 runghc --package minio-hs --package optparse-applicative --package filepath
62-- MinIO Haskell SDK, (C) 2017-2019 MinIO, Inc.
64-- Licensed under the Apache License, Version 2.0 (the "License");
65-- you may not use this file except in compliance with the License.
66-- You may obtain a copy of the License at
68-- http://www.apache.org/licenses/LICENSE-2.0
70-- Unless required by applicable law or agreed to in writing, software
71-- distributed under the License is distributed on an "AS IS" BASIS,
72-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
73-- See the License for the specific language governing permissions and
74-- limitations under the License.
78{-# LANGUAGE OverloadedStrings #-}
79{-# LANGUAGE ScopedTypeVariables #-}
82import Data.Monoid ((<>))
83import Data.Text (pack)
84import Options.Applicative
85import System.FilePath.Posix
86import UnliftIO (throwIO, try)
90-- | The following example uses minio's play server at
91-- https://play.min.io. The endpoint and associated
92-- credentials are provided via the libary constant,
94-- > minioPlayCI :: ConnectInfo
97-- optparse-applicative package based command-line parsing.
98fileNameArgs :: Parser FilePath
99fileNameArgs = strArgument
101 <> help "Name of file to upload to AWS S3 or a MinIO server")
104 (helper <*> fileNameArgs)
106 <> progDesc "FileUploader"
108 "FileUploader - a simple file-uploader program using minio-hs")
112 let bucket = "my-bucket"
114 -- Parse command line argument
115 filepath <- execParser cmdParser
116 let object = pack $ takeBaseName filepath
118 res <- runMinio minioPlayCI $ do
119 -- Make a bucket; catch bucket already exists exception if thrown.
120 bErr <- try $ makeBucket bucket Nothing
122 -- If the bucket already exists, we would get a specific
123 -- `ServiceErr` exception thrown.
125 Left BucketAlreadyOwnedByYou -> return ()
129 -- Upload filepath to bucket; object name is derived from filepath.
130 fPutObject bucket object filepath defaultPutObjectOptions
133 Left e -> putStrLn $ "file upload failed due to " ++ show e
134 Right () -> putStrLn "file upload succeeded."
140./FileUploader.hs "path/to/my/file"
146[Contributors Guide](https://github.com/minio/minio-hs/blob/master/CONTRIBUTING.md)
150#### Download the source
153$ git clone https://github.com/minio/minio-hs.git
157#### Build the package:
162$ # Configure cabal for development enabling all optional flags defined by the package.
163$ cabal configure --enable-tests --test-show-details=direct -fexamples -fdev -flive-test
170$ stack build --test --no-run-tests --flag minio-hs:live-test --flag minio-hs:dev --flag minio-hs:examples
174A section of the tests use the remote MinIO Play server at `https://play.min.io` 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` with the credentials `access_key=minio` and `secret_key=minio123`, just set the environment `MINIO_LOCAL` to any value (and unset it to switch back to Play).
179$ export MINIO_LOCAL=1 # to run live tests against local MinIO server
186$ export MINIO_LOCAL=1 # to run live tests against local MinIO server
187stack test --flag minio-hs:live-test --flag minio-hs:dev
190This will run all the test suites.
192#### Building documentation:
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list