diff --git a/examples/getObject.hs b/examples/getObject.hs new file mode 100755 index 0000000..6eb20bb --- /dev/null +++ b/examples/getObject.hs @@ -0,0 +1,28 @@ +#!/usr/bin/env stack +-- stack --resolver lts-6.27 runghc --package minio-hs + + +{-# Language OverloadedStrings #-} +import Network.Minio + +import qualified Data.Conduit as C +import qualified Data.Conduit.Binary as CB +import Prelude + +-- | 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 +-- + +main :: IO () +main = do + let + bucket = "krisis" + object = "fail.out" + res <- runResourceT $ runMinio minioPlayCI $ do + (_, src) <- getObject bucket object [] [] + (src C.$$+- CB.sinkLbs) + + print res diff --git a/examples/putObject.hs b/examples/putObject.hs new file mode 100755 index 0000000..dd81a39 --- /dev/null +++ b/examples/putObject.hs @@ -0,0 +1,37 @@ +#!/usr/bin/env stack +-- stack --resolver lts-6.27 runghc --package minio-hs + +{-# Language OverloadedStrings #-} +import Network.Minio + +import qualified Data.Conduit.Combinators as CC +import Prelude + +-- | 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 +-- + +main :: IO () +main = do + let + bucket = "test" + object = "obj" + mb15 = 15 * 1024 * 1024 + + -- Eg 1. Upload a stream of repeating "a" using putObjectFromSource. + res1 <- runResourceT $ runMinio minioPlayCI $ do + putObjectFromSource bucket object (CC.repeat "a") (Just mb15) + case res1 of + Left e -> putStrLn $ "putObjectFromSource failed." ++ (show e) + Right () -> putStrLn "putObjectFromSource succeeded." + + + -- Eg 2. Upload a file using fPutObject. + res2 <- runResourceT $ runMinio minioPlayCI $ do + fPutObject bucket object "path/to/local/file" + case res2 of + Left e -> putStrLn $ "fPutObject failed." ++ (show e) + Right () -> putStrLn "fPutObject succeeded." diff --git a/src/Network/Minio.hs b/src/Network/Minio.hs index a7a8b7a..a1fdd86 100644 --- a/src/Network/Minio.hs +++ b/src/Network/Minio.hs @@ -2,8 +2,8 @@ module Network.Minio ( ConnectInfo(..) - , aws - , play + , awsCI + , minioPlayCI , connect , Minio @@ -35,6 +35,7 @@ module Network.Minio , putObjectFromSource , ObjectData(..) + , getObject , putObject , listObjects diff --git a/src/Network/Minio/Data.hs b/src/Network/Minio/Data.hs index 53e7619..5044905 100644 --- a/src/Network/Minio/Data.hs +++ b/src/Network/Minio/Data.hs @@ -30,8 +30,8 @@ instance Default ConnectInfo where -- | -- Default aws ConnectInfo. Credentials should be supplied before use. -aws :: ConnectInfo -aws = def { +awsCI :: ConnectInfo +awsCI = def { connectHost = "s3.amazonaws.com" , connectPort = 443 , connectAccessKey = "" @@ -41,8 +41,8 @@ aws = def { -- | -- Default minio play server ConnectInfo. Credentials are already filled. -play :: ConnectInfo -play = def { +minioPlayCI :: ConnectInfo +minioPlayCI = def { connectHost = "play.minio.io" , connectPort = 9000 , connectAccessKey = "Q3AM3UQ867SPQQA43P2F" diff --git a/test/Spec.hs b/test/Spec.hs index fe3a9a1..06b569f 100644 --- a/test/Spec.hs +++ b/test/Spec.hs @@ -113,8 +113,9 @@ liveServerUnitTests = testGroup "Unit tests against a live server" step "singlepart putObject works" fPutObject bucket "lsb-release" "/etc/lsb-release" + outFile <- mkRandFile 0 step "simple getObject works" - fGetObject bucket "lsb-release" "/tmp/out" + fGetObject bucket "lsb-release" outFile step "create new multipart upload works" uid <- newMultipartUpload bucket "newmpupload" [] @@ -242,7 +243,8 @@ liveServerUnitTests = testGroup "Unit tests against a live server" liftIO $ (T.length uid > 0) @? ("Got an empty multipartUpload Id.") step "put object parts 1..10" - h <- liftIO $ SIO.openBinaryFile "/tmp/inputfile" SIO.ReadMode + inputFile <- mkRandFile mb15 + h <- liftIO $ SIO.openBinaryFile inputFile SIO.ReadMode forM [1..10] $ \pnum -> putObjectPart bucket object uid pnum [] $ PayloadH h 0 mb15 @@ -292,7 +294,8 @@ liveServerUnitTests = testGroup "Unit tests against a live server" liftIO $ (T.length uid > 0) @? ("Got an empty multipartUpload Id.") step "put object parts 1..10" - h <- liftIO $ SIO.openBinaryFile "/tmp/inputfile" SIO.ReadMode + inputFile <- mkRandFile mb15 + h <- liftIO $ SIO.openBinaryFile inputFile SIO.ReadMode forM [1..10] $ \pnum -> putObjectPart bucket object uid pnum [] $ PayloadH h 0 mb15