minio-hs/docs/API.md
Krishnan Parthasarathi 8efd9f2329 Export getService S3API as listBuckets (#18)
... for parity with other SDKs.

- Also remove left-over reference of listIncompleteParts.
2017-03-02 12:11:34 +05:30

7.8 KiB

Minio Haskell SDK API Reference

Initialize Minio Client object.

This SDK provides helpers to connect to play.minio.io (the public Minio Play server), the AWS S3 service, and to a locally hosted Minio server.

For Play, use

minioPlayCI :: ConnectInfo
minioPlayCI

For AWS S3, use

awsCI :: ConnectInfo
awsCI { connectAccesskey = "your-access-key"
      , connectSecretkey = "your-secret-key"
      }

For a local Minio server instance running at localhost:9000 with "minio" and "minio123" as access key and secret key respectively, use

def :: ConnectInfo
def

For a minio server instance deployed with custom configuration, use

def :: ConnectInfo
def { connectHost = "host"
    , connectPort = 5000
    , connectAccessKey = "access-key"
    , connectSecretKey = "secret-key"
    , connectIsSecure = False
    }
Bucket operations Object Operations
listBuckets getObject
makeBucket putObject
removeBucket fGetObject
listObjects fPutObject
listIncompleteUploads copyObject
removeObject

1. ConnectInfo smart constructors

2. Bucket operations

listBuckets :: Minio [BucketInfo]

Lists buckets.

Return Value

Return type Description
Minio [BucketInfo] List of buckets

BucketInfo record type

Field Type Description
biName Bucket (alias of Text) Name of the bucket
biCreationDate UTCTime Creation time of the bucket

makeBucket :: Bucket -> Maybe Region -> Minio ()

Create a new bucket. If the region is not specified, the region specified by ConnectInfo is used.

Parameters

In the expression makeBucket bucketName region the arguments are:

Param Type Description
bucketName Bucket (alias for Text) Name of the bucket
region Maybe Region Region where the bucket is to be created. If not specified, default to the region in ConnectInfo.

Example

{-# Language OverloadedStrings #-}
main :: IO ()
main = do
    res <- runResourceT $ runMinio minioPlayCI $ do
        makeBucket bucketName (Just "us-east-1")

    case res of
        Left err -> putStrLn $ "Failed to make bucket: " ++ (show res)
        Right _ -> putStrLn $ "makeBucket successful."

removeBucket :: Bucket -> Minio ()

Remove a bucket. The bucket must be empty or an error will be thrown.

Parameters

In the expression removeBucket bucketName the arguments are:

Param Type Description
bucketName Bucket (alias for Text) Name of the bucket

Example

{-# Language OverloadedStrings #-}
main :: IO ()
main = do
    res <- runResourceT $ runMinio minioPlayCI $ do
        removeBucket "mybucket"

    case res of
        Left err -> putStrLn $ "Failed to remove bucket: " ++ (show res)
        Right _ -> putStrLn $ "removeBucket successful."

listObjects :: Bucket -> Maybe Text -> Bool -> C.Producer Minio ObjectInfo

List objects in the given bucket.

Parameters

In the expression listObjects bucketName prefix recursive the arguments are:

Param Type Description
bucketName Bucket (alias for Text) Name of the bucket
prefix Maybe Text Optional prefix that listed objects should have
recursive Bool True indicates recursive style listing and False indicates directory style listing delimited by '/'.

Return Value

Return type Description
C.Producer Minio ObjectInfo A Conduit Producer of ObjectInfo values corresponding to each incomplete multipart upload

ObjectInfo record type

Field Type Description
oiObject Object (alias for Text) Name of object
oiModTime UTCTime Last modified time of the object
oiETag ETag (alias for Text) ETag of the object
oiSize Int64 Size of the object in bytes

Example

import Data.Conduit ($$)
import Conduit.Combinators (sinkList)

main :: IO ()
main = do
  let
    bucket = "test"

  -- Performs a recursive listing of all objects under bucket "test"
  -- on play.minio.io.
  res <- runResourceT $ runMinio minioPlayCI $ do
    listObjects bucket Nothing True $$ sinkList
  print res

listIncompleteUploads :: Bucket -> Maybe Prefix -> Bool -> C.Producer Minio UploadInfo

List incompletely uploaded objects.

Parameters

In the expression listIncompleteUploads bucketName prefix recursive the parameters are:

Param Type Description
bucketName Bucket (alias for Text) Name of the bucket
prefix Maybe Text Optional prefix that listed objects should have.
recursive Bool True indicates recursive style listing and Talse indicates directory style listing delimited by '/'.

Return Value

Return type Description
C.Producer Minio UploadInfo A Conduit Producer of UploadInfo values corresponding to each incomplete multipart upload

UploadInfo record type

Field Type Description
uiKey Object Name of incompletely uploaded object
uiUploadId String Upload ID of incompletely uploaded object
uiSize Int64 Size of incompletely uploaded object

Example

import Data.Conduit ($$)
import Conduit.Combinators (sinkList)

main :: IO ()
main = do
  let
    bucket = "test"

  -- Performs a recursive listing of all incompletely uploaded objects
  -- under bucket "test" on play.minio.io.
  res <- runResourceT $ runMinio minioPlayCI $ do
    listIncompleteUploads bucket Nothing True $$ sinkList
  print res

3. Object operations

getObject :: Bucket -> Object -> Minio (C.ResumableSource Minio ByteString)

Get an object from the service.

Parameters

In the expression getObject bucketName objectName the parameters are:

Param Type Description
bucketName Bucket (alias for Text) Name of the bucket
objectName Object (alias for Text) Name of the object

Return Value

The return value can be incrementally read to process the contents of the object.

Return type Description
C.ResumableSource Minio ByteString A Conduit ResumableSource of ByteString values.

Example


import Data.Conduit ($$+-)
import Data.Conduit.Binary (sinkLbs)

main :: IO ()
main = do
  let
    bucket = "mybucket"
    object = "myobject"

  -- Lists the parts in an incompletely uploaded object identified by
  -- bucket, object and upload ID.
  res <- runResourceT $ runMinio minioPlayCI $ do
           source <- getObject bucket object
           src $$+- sinkLbs

  -- the following the prints the contents of the object.
  print res

putObject :: Bucket -> Object -> C.Producer Minio ByteString -> Maybe Int64 -> Minio ()

fGetObject :: Bucket -> Object -> FilePath -> Minio ()

fPutObject :: Bucket -> Object -> FilePath -> Minio ()

copyObject :: Bucket -> Object -> CopyPartSource -> Minio ()

removeObject :: Bucket -> Object -> Minio ()