Add getObject and putObject examples
- Use mkRandFile instead of depending on files on disk.
This commit is contained in:
parent
0509d90ef1
commit
fd66d85167
28
examples/getObject.hs
Executable file
28
examples/getObject.hs
Executable file
@ -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
|
||||
37
examples/putObject.hs
Executable file
37
examples/putObject.hs
Executable file
@ -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."
|
||||
@ -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
|
||||
|
||||
@ -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"
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user