Fix examples to point to lts-11.1 and update docs (#98)
This commit is contained in:
parent
7564cbd514
commit
22808fcdaf
54
README.md
54
README.md
@ -44,18 +44,36 @@ stack haddock
|
|||||||
### FileUploader.hs
|
### FileUploader.hs
|
||||||
``` haskell
|
``` haskell
|
||||||
#!/usr/bin/env stack
|
#!/usr/bin/env stack
|
||||||
-- stack --resolver lts-9.1 runghc --package minio-hs --package optparse-applicative --package filepath
|
-- stack --resolver lts-11.1 runghc --package minio-hs --package optparse-applicative --package filepath
|
||||||
|
|
||||||
{-# Language OverloadedStrings, ScopedTypeVariables #-}
|
--
|
||||||
import Network.Minio
|
-- Minio Haskell SDK, (C) 2017, 2018 Minio, Inc.
|
||||||
|
--
|
||||||
|
-- Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
-- you may not use this file except in compliance with the License.
|
||||||
|
-- You may obtain a copy of the License at
|
||||||
|
--
|
||||||
|
-- http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
--
|
||||||
|
-- Unless required by applicable law or agreed to in writing, software
|
||||||
|
-- distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
-- See the License for the specific language governing permissions and
|
||||||
|
-- limitations under the License.
|
||||||
|
--
|
||||||
|
|
||||||
import Control.Monad.Catch (catchIf)
|
|
||||||
import Control.Monad.IO.Class (liftIO)
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
import Data.Monoid ((<>))
|
{-# LANGUAGE ScopedTypeVariables #-}
|
||||||
import Data.Text (pack)
|
import Network.Minio
|
||||||
import Options.Applicative
|
|
||||||
import Prelude
|
import Data.Monoid ((<>))
|
||||||
import System.FilePath.Posix
|
import Data.Text (pack)
|
||||||
|
import Options.Applicative
|
||||||
|
import System.FilePath.Posix
|
||||||
|
import UnliftIO (throwIO, try)
|
||||||
|
|
||||||
|
import Prelude
|
||||||
|
|
||||||
-- | The following example uses minio's play server at
|
-- | The following example uses minio's play server at
|
||||||
-- https://play.minio.io:9000. The endpoint and associated
|
-- https://play.minio.io:9000. The endpoint and associated
|
||||||
@ -77,27 +95,27 @@ cmdParser = info
|
|||||||
<> header
|
<> header
|
||||||
"FileUploader - a simple file-uploader program using minio-hs")
|
"FileUploader - a simple file-uploader program using minio-hs")
|
||||||
|
|
||||||
ignoreMinioErr :: ServiceErr -> Minio ()
|
|
||||||
ignoreMinioErr = return . const ()
|
|
||||||
|
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = do
|
||||||
let bucket = "my-bucket"
|
let bucket = "my-bucket"
|
||||||
|
|
||||||
-- Parse command line argument, namely --filename.
|
-- Parse command line argument
|
||||||
filepath <- execParser cmdParser
|
filepath <- execParser cmdParser
|
||||||
let object = pack $ takeBaseName filepath
|
let object = pack $ takeBaseName filepath
|
||||||
|
|
||||||
res <- runMinio minioPlayCI $ do
|
res <- runMinio minioPlayCI $ do
|
||||||
-- Make a bucket; catch bucket already exists exception if thrown.
|
-- Make a bucket; catch bucket already exists exception if thrown.
|
||||||
catchIf (== BucketAlreadyOwnedByYou) (makeBucket bucket Nothing) ignoreMinioErr
|
bErr <- try $ makeBucket bucket Nothing
|
||||||
|
case bErr of
|
||||||
|
Left (MErrService BucketAlreadyOwnedByYou) -> return ()
|
||||||
|
Left e -> throwIO e
|
||||||
|
Right _ -> return ()
|
||||||
|
|
||||||
-- Upload filepath to bucket; object is derived from filepath.
|
-- Upload filepath to bucket; object is derived from filepath.
|
||||||
fPutObject bucket object filepath
|
fPutObject bucket object filepath def
|
||||||
|
|
||||||
case res of
|
case res of
|
||||||
Left e -> putStrLn $ "file upload failed due to " ++ (show e)
|
Left e -> putStrLn $ "file upload failed due to " ++ (show e)
|
||||||
Right () -> putStrLn "file upload succeeded."
|
Right () -> putStrLn "file upload succeeded."
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
170
docs/API.md
170
docs/API.md
@ -185,7 +185,6 @@ main :: IO ()
|
|||||||
main = do
|
main = do
|
||||||
res <- runMinio minioPlayCI $ do
|
res <- runMinio minioPlayCI $ do
|
||||||
makeBucket bucketName (Just "us-east-1")
|
makeBucket bucketName (Just "us-east-1")
|
||||||
|
|
||||||
case res of
|
case res of
|
||||||
Left err -> putStrLn $ "Failed to make bucket: " ++ (show res)
|
Left err -> putStrLn $ "Failed to make bucket: " ++ (show res)
|
||||||
Right _ -> putStrLn $ "makeBucket successful."
|
Right _ -> putStrLn $ "makeBucket successful."
|
||||||
@ -225,7 +224,7 @@ main = do
|
|||||||
|
|
||||||
|
|
||||||
<a name="listObjects"></a>
|
<a name="listObjects"></a>
|
||||||
### listObjects :: Bucket -> Maybe Text -> Bool -> C.Producer Minio ObjectInfo
|
### listObjects :: Bucket -> Maybe Text -> Bool -> C.ConduitM () ObjectInfo Minio ()
|
||||||
|
|
||||||
List objects in the given bucket, implements version 2 of AWS S3 API.
|
List objects in the given bucket, implements version 2 of AWS S3 API.
|
||||||
|
|
||||||
@ -244,7 +243,7 @@ __Return Value__
|
|||||||
|
|
||||||
|Return type |Description |
|
|Return type |Description |
|
||||||
|:---|:---|
|
|:---|:---|
|
||||||
| _C.Producer Minio ObjectInfo_ | A Conduit Producer of `ObjectInfo` values corresponding to each object. |
|
| _C.ConduitM () ObjectInfo Minio ()_ | A Conduit Producer of `ObjectInfo` values corresponding to each object. |
|
||||||
|
|
||||||
__ObjectInfo record type__
|
__ObjectInfo record type__
|
||||||
|
|
||||||
@ -258,10 +257,19 @@ __ObjectInfo record type__
|
|||||||
__Example__
|
__Example__
|
||||||
|
|
||||||
``` haskell
|
``` haskell
|
||||||
{-# Language OverloadedStrings #-}
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
|
import Network.Minio
|
||||||
|
|
||||||
import Data.Conduit (($$))
|
import Conduit
|
||||||
import Conduit.Combinators (sinkList)
|
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 :: IO ()
|
||||||
main = do
|
main = do
|
||||||
@ -270,14 +278,13 @@ main = do
|
|||||||
|
|
||||||
-- Performs a recursive listing of all objects under bucket "test"
|
-- Performs a recursive listing of all objects under bucket "test"
|
||||||
-- on play.minio.io.
|
-- on play.minio.io.
|
||||||
res <- runMinio minioPlayCI $ do
|
res <- runMinio minioPlayCI $
|
||||||
listObjects bucket Nothing True $$ sinkList
|
runConduit $ listObjects bucket Nothing True .| mapM_C (\v -> (liftIO $ print v))
|
||||||
print res
|
print res
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
<a name="listObjectsV1"></a>
|
<a name="listObjectsV1"></a>
|
||||||
### listObjectsV1 :: Bucket -> Maybe Text -> Bool -> C.Producer Minio ObjectInfo
|
### listObjectsV1 :: Bucket -> Maybe Text -> Bool -> C.ConduitM () ObjectInfo Minio ()
|
||||||
|
|
||||||
List objects in the given bucket, implements version 1 of AWS S3 API. This API
|
List objects in the given bucket, implements version 1 of AWS S3 API. This API
|
||||||
is provided for legacy S3 compatible object storage endpoints.
|
is provided for legacy S3 compatible object storage endpoints.
|
||||||
@ -297,7 +304,7 @@ __Return Value__
|
|||||||
|
|
||||||
|Return type |Description |
|
|Return type |Description |
|
||||||
|:---|:---|
|
|:---|:---|
|
||||||
| _C.Producer Minio ObjectInfo_ | A Conduit Producer of `ObjectInfo` values corresponding to each object. |
|
| _C.ConduitM () ObjectInfo Minio ()_ | A Conduit Producer of `ObjectInfo` values corresponding to each object. |
|
||||||
|
|
||||||
__ObjectInfo record type__
|
__ObjectInfo record type__
|
||||||
|
|
||||||
@ -311,10 +318,19 @@ __ObjectInfo record type__
|
|||||||
__Example__
|
__Example__
|
||||||
|
|
||||||
``` haskell
|
``` haskell
|
||||||
{-# Language OverloadedStrings #-}
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
|
import Network.Minio
|
||||||
|
|
||||||
import Data.Conduit (($$))
|
import Conduit
|
||||||
import Conduit.Combinators (sinkList)
|
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 :: IO ()
|
||||||
main = do
|
main = do
|
||||||
@ -323,10 +339,9 @@ main = do
|
|||||||
|
|
||||||
-- Performs a recursive listing of all objects under bucket "test"
|
-- Performs a recursive listing of all objects under bucket "test"
|
||||||
-- on play.minio.io.
|
-- on play.minio.io.
|
||||||
res <- runMinio minioPlayCI $ do
|
res <- runMinio minioPlayCI $
|
||||||
listObjectsV1 bucket Nothing True $$ sinkList
|
runConduit $ listObjectsV1 bucket Nothing True .| mapM_C (\v -> (liftIO $ print v))
|
||||||
print res
|
print res
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
<a name="listIncompleteUploads"></a>
|
<a name="listIncompleteUploads"></a>
|
||||||
@ -349,7 +364,7 @@ __Return Value__
|
|||||||
|
|
||||||
|Return type |Description |
|
|Return type |Description |
|
||||||
|:---|:---|
|
|:---|:---|
|
||||||
| _C.Producer Minio UploadInfo_ | A Conduit Producer of `UploadInfo` values corresponding to each incomplete multipart upload |
|
| _C.ConduitM () UploadInfo Minio ()_ | A Conduit Producer of `UploadInfo` values corresponding to each incomplete multipart upload |
|
||||||
|
|
||||||
__UploadInfo record type__
|
__UploadInfo record type__
|
||||||
|
|
||||||
@ -362,20 +377,28 @@ __UploadInfo record type__
|
|||||||
__Example__
|
__Example__
|
||||||
|
|
||||||
```haskell
|
```haskell
|
||||||
{-# Language OverloadedStrings #-}
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
|
import Network.Minio
|
||||||
|
|
||||||
import Data.Conduit (($$))
|
import Conduit
|
||||||
import Conduit.Combinators (sinkList)
|
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 :: IO ()
|
||||||
main = do
|
main = do
|
||||||
let
|
let
|
||||||
bucket = "test"
|
bucket = "test"
|
||||||
|
|
||||||
-- Performs a recursive listing of all incompletely uploaded objects
|
-- Performs a recursive listing of incomplete uploads under bucket "test"
|
||||||
-- under bucket "test" on play.minio.io.
|
-- on a local minio server.
|
||||||
res <- runMinio minioPlayCI $ do
|
res <- runMinio minioPlayCI $
|
||||||
listIncompleteUploads bucket Nothing True $$ sinkList
|
runConduit $ listIncompleteUploads bucket Nothing True .| mapM_C (\v -> (liftIO $ print v))
|
||||||
print res
|
print res
|
||||||
|
|
||||||
```
|
```
|
||||||
@ -383,19 +406,30 @@ main = do
|
|||||||
## 3. Object operations
|
## 3. Object operations
|
||||||
|
|
||||||
<a name="getObject"></a>
|
<a name="getObject"></a>
|
||||||
### getObject :: Bucket -> Object -> Minio (C.ResumableSource Minio ByteString)
|
### getObject :: Bucket -> Object -> GetObjectOptions -> Minio (C.ConduitM () ByteString Minio ())
|
||||||
|
|
||||||
Get an object from the service.
|
Get an object from the S3 service, optionally object ranges can be provided as well.
|
||||||
|
|
||||||
__Parameters__
|
__Parameters__
|
||||||
|
|
||||||
In the expression `getObject bucketName objectName` the parameters
|
In the expression `getObject bucketName objectName opts` the parameters
|
||||||
are:
|
are:
|
||||||
|
|
||||||
|Param |Type |Description |
|
|Param |Type |Description |
|
||||||
|:---|:---| :---|
|
|:---|:---| :---|
|
||||||
| `bucketName` | _Bucket_ (alias for `Text`) | Name of the bucket |
|
| `bucketName` | _Bucket_ (alias for `Text`) | Name of the bucket |
|
||||||
| `objectName` | _Object_ (alias for `Text`) | Name of the object |
|
| `objectName` | _Object_ (alias for `Text`) | Name of the object |
|
||||||
|
| `opts` | _GetObjectOptions_ | Options for GET requests specifying additional options like If-Match, Range |
|
||||||
|
|
||||||
|
__GetObjectOptions record type__
|
||||||
|
|
||||||
|
|Field |Type |Description |
|
||||||
|
|:---|:---| :---|
|
||||||
|
| `gooRange` | `Maybe ByteRanges` | Represents the byte range of object. E.g ByteRangeFromTo 0 9 represents first ten bytes of the object|
|
||||||
|
| `gooIfMatch` | `Maybe ETag` (alias for `Text`) | (Optional) ETag of object should match |
|
||||||
|
| `gooIfNoneMatch` | `Maybe ETag` (alias for `Text`) | (Optional) ETag of object shouldn't match |
|
||||||
|
| `gooIfUnmodifiedSince` | `Maybe UTCTime` | (Optional) Time since object wasn't modified |
|
||||||
|
| `gooIfModifiedSince` | `Maybe UTCTime` | (Optional) Time since object was modified |
|
||||||
|
|
||||||
__Return Value__
|
__Return Value__
|
||||||
|
|
||||||
@ -403,41 +437,45 @@ The return value can be incrementally read to process the contents of
|
|||||||
the object.
|
the object.
|
||||||
|Return type |Description |
|
|Return type |Description |
|
||||||
|:---|:---|
|
|:---|:---|
|
||||||
| _C.ResumableSource Minio ByteString_ | A Conduit ResumableSource of `ByteString` values. |
|
| _Minio (C.ConduitM () ByteString Minio ())_ | A Conduit source of `ByteString` values. |
|
||||||
|
|
||||||
__Example__
|
__Example__
|
||||||
|
|
||||||
```haskell
|
```haskell
|
||||||
{-# Language OverloadedStrings #-}
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
|
import Network.Minio
|
||||||
|
|
||||||
import Network.Minio
|
import qualified Data.Conduit as C
|
||||||
import Data.Conduit (($$+-))
|
import qualified Data.Conduit.Binary as CB
|
||||||
import Data.Conduit.Binary (sinkLbs)
|
|
||||||
import qualified Data.ByteString.Lazy as LB
|
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 :: IO ()
|
||||||
main = do
|
main = do
|
||||||
let
|
let
|
||||||
bucket = "mybucket"
|
bucket = "my-bucket"
|
||||||
object = "myobject"
|
object = "my-object"
|
||||||
|
|
||||||
-- Lists the parts in an incompletely uploaded object identified by
|
|
||||||
-- bucket, object and upload ID.
|
|
||||||
res <- runMinio minioPlayCI $ do
|
res <- runMinio minioPlayCI $ do
|
||||||
source <- getObject bucket object
|
src <- getObject bucket object def
|
||||||
source $$+- sinkLbs
|
C.connect src $ CB.sinkFileCautious "/tmp/my-object"
|
||||||
|
|
||||||
-- the following the prints the contents of the object.
|
case res of
|
||||||
putStrLn $ either
|
Left e -> putStrLn $ "getObject failed." ++ (show e)
|
||||||
(("Failed to getObject: " ++) . show)
|
Right _ -> putStrLn "getObject succeeded."
|
||||||
(("Read an object of length: " ++) . show . LB.length)
|
|
||||||
res
|
|
||||||
```
|
```
|
||||||
|
|
||||||
<a name="putObject"></a>
|
<a name="putObject"></a>
|
||||||
### putObject :: Bucket -> Object -> C.Producer Minio ByteString -> Maybe Int64 -> Minio ()
|
### putObject :: Bucket -> Object -> C.ConduitM () ByteString Minio () -> Maybe Int64 -> PutObjectOptions -> Minio ()
|
||||||
Uploads an object to a bucket in the service, from the given input
|
Uploads an object to a bucket in the service, from the given input
|
||||||
byte stream of optionally supplied length
|
byte stream of optionally supplied length. Optionally you can also specify
|
||||||
|
additional metadata for the object.
|
||||||
|
|
||||||
__Parameters__
|
__Parameters__
|
||||||
|
|
||||||
@ -448,28 +486,42 @@ are:
|
|||||||
|:---|:---| :---|
|
|:---|:---| :---|
|
||||||
| `bucketName` | _Bucket_ (alias for `Text`) | Name of the bucket |
|
| `bucketName` | _Bucket_ (alias for `Text`) | Name of the bucket |
|
||||||
| `objectName` | _Object_ (alias for `Text`) | Name of the object |
|
| `objectName` | _Object_ (alias for `Text`) | Name of the object |
|
||||||
| `inputSrc` | _C.Producer Minio ByteString_ | A Conduit Producer of `ByteString` values |
|
| `inputSrc` | _C.ConduitM () ByteString Minio ()_ | A Conduit producer of `ByteString` values |
|
||||||
|
| `size` | _Int64_ | Provide stream size (optional) |
|
||||||
|
| `opts` | _PutObjectOptions_ | Optional parameters to provide additional metadata for the object |
|
||||||
|
|
||||||
__Example__
|
__Example__
|
||||||
|
|
||||||
```haskell
|
```haskell
|
||||||
{-# Language OverloadedStrings #-}
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
import Network.Minio
|
import Network.Minio
|
||||||
|
|
||||||
import qualified Data.Conduit.Combinators as CC
|
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 :: IO ()
|
||||||
main = do
|
main = do
|
||||||
let
|
let
|
||||||
bucket = "mybucket"
|
bucket = "test"
|
||||||
object = "myobject"
|
object = "obj"
|
||||||
kb15 = 15 * 1024
|
localFile = "/etc/lsb-release"
|
||||||
|
kb15 = 15 * 1024
|
||||||
res <- runMinio minioPlayCI $ do
|
|
||||||
putObject bucket object (CC.repeat "a") (Just kb15)
|
|
||||||
|
|
||||||
|
-- Eg 1. Upload a stream of repeating "a" using putObject with default options.
|
||||||
|
res <- runMinio minioPlayCI $
|
||||||
|
putObject bucket object (CC.repeat "a") (Just kb15) def
|
||||||
case res of
|
case res of
|
||||||
Left e -> putStrLn $ "Failed to putObject " ++ show bucket ++ "/" ++ show object
|
Left e -> putStrLn $ "putObject failed." ++ show e
|
||||||
Right _ -> putStrLn "PutObject was successful"
|
Right () -> putStrLn "putObject succeeded."
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
<a name="fGetObject"></a>
|
<a name="fGetObject"></a>
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
#!/usr/bin/env stack
|
#!/usr/bin/env stack
|
||||||
-- stack --resolver lts-9.1 runghc --package minio-hs
|
-- stack --resolver lts-11.1 runghc --package minio-hs
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Minio Haskell SDK, (C) 2017 Minio, Inc.
|
-- Minio Haskell SDK, (C) 2017, 2018 Minio, Inc.
|
||||||
--
|
--
|
||||||
-- Licensed under the Apache License, Version 2.0 (the "License");
|
-- Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
-- you may not use this file except in compliance with the License.
|
-- you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
#!/usr/bin/env stack
|
#!/usr/bin/env stack
|
||||||
-- stack --resolver lts-9.1 runghc --package minio-hs
|
-- stack --resolver lts-11.1 runghc --package minio-hs
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Minio Haskell SDK, (C) 2017 Minio, Inc.
|
-- Minio Haskell SDK, (C) 2017, 2018 Minio, Inc.
|
||||||
--
|
--
|
||||||
-- Licensed under the Apache License, Version 2.0 (the "License");
|
-- Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
-- you may not use this file except in compliance with the License.
|
-- you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
#!/usr/bin/env stack
|
#!/usr/bin/env stack
|
||||||
-- stack --resolver lts-9.1 runghc --package minio-hs --package optparse-applicative --package filepath
|
-- stack --resolver lts-11.1 runghc --package minio-hs --package optparse-applicative --package filepath
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Minio Haskell SDK, (C) 2017 Minio, Inc.
|
-- Minio Haskell SDK, (C) 2017, 2018 Minio, Inc.
|
||||||
--
|
--
|
||||||
-- Licensed under the Apache License, Version 2.0 (the "License");
|
-- Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
-- you may not use this file except in compliance with the License.
|
-- you may not use this file except in compliance with the License.
|
||||||
@ -22,13 +22,13 @@
|
|||||||
{-# LANGUAGE ScopedTypeVariables #-}
|
{-# LANGUAGE ScopedTypeVariables #-}
|
||||||
import Network.Minio
|
import Network.Minio
|
||||||
|
|
||||||
import Control.Monad.Catch (catchIf)
|
import Data.Monoid ((<>))
|
||||||
import Control.Monad.IO.Class (liftIO)
|
import Data.Text (pack)
|
||||||
import Data.Monoid ((<>))
|
|
||||||
import Data.Text (pack)
|
|
||||||
import Options.Applicative
|
import Options.Applicative
|
||||||
import Prelude
|
|
||||||
import System.FilePath.Posix
|
import System.FilePath.Posix
|
||||||
|
import UnliftIO (throwIO, try)
|
||||||
|
|
||||||
|
import Prelude
|
||||||
|
|
||||||
-- | The following example uses minio's play server at
|
-- | The following example uses minio's play server at
|
||||||
-- https://play.minio.io:9000. The endpoint and associated
|
-- https://play.minio.io:9000. The endpoint and associated
|
||||||
@ -50,10 +50,6 @@ cmdParser = info
|
|||||||
<> header
|
<> header
|
||||||
"FileUploader - a simple file-uploader program using minio-hs")
|
"FileUploader - a simple file-uploader program using minio-hs")
|
||||||
|
|
||||||
ignoreMinioErr :: ServiceErr -> Minio ()
|
|
||||||
ignoreMinioErr = return . const ()
|
|
||||||
|
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = do
|
||||||
let bucket = "my-bucket"
|
let bucket = "my-bucket"
|
||||||
@ -64,10 +60,14 @@ main = do
|
|||||||
|
|
||||||
res <- runMinio minioPlayCI $ do
|
res <- runMinio minioPlayCI $ do
|
||||||
-- Make a bucket; catch bucket already exists exception if thrown.
|
-- Make a bucket; catch bucket already exists exception if thrown.
|
||||||
catchIf (== BucketAlreadyOwnedByYou) (makeBucket bucket Nothing) ignoreMinioErr
|
bErr <- try $ makeBucket bucket Nothing
|
||||||
|
case bErr of
|
||||||
|
Left (MErrService BucketAlreadyOwnedByYou) -> return ()
|
||||||
|
Left e -> throwIO e
|
||||||
|
Right _ -> return ()
|
||||||
|
|
||||||
-- Upload filepath to bucket; object is derived from filepath.
|
-- Upload filepath to bucket; object is derived from filepath.
|
||||||
fPutObject bucket object filepath
|
fPutObject bucket object filepath def
|
||||||
|
|
||||||
case res of
|
case res of
|
||||||
Left e -> putStrLn $ "file upload failed due to " ++ (show e)
|
Left e -> putStrLn $ "file upload failed due to " ++ (show e)
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
-- stack --resolver lts-11.1 runghc --package minio-hs
|
-- stack --resolver lts-11.1 runghc --package minio-hs
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Minio Haskell SDK, (C) 2018 Minio, Inc.
|
-- Minio Haskell SDK, (C) 2017, 2018 Minio, Inc.
|
||||||
--
|
--
|
||||||
-- Licensed under the Apache License, Version 2.0 (the "License");
|
-- Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
-- you may not use this file except in compliance with the License.
|
-- you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
#!/usr/bin/env stack
|
#!/usr/bin/env stack
|
||||||
-- stack --resolver lts-9.1 runghc --package minio-hs
|
-- stack --resolver lts-11.1 runghc --package minio-hs
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Minio Haskell SDK, (C) 2017 Minio, Inc.
|
-- Minio Haskell SDK, (C) 2017, 2018 Minio, Inc.
|
||||||
--
|
--
|
||||||
-- Licensed under the Apache License, Version 2.0 (the "License");
|
-- Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
-- you may not use this file except in compliance with the License.
|
-- you may not use this file except in compliance with the License.
|
||||||
@ -20,8 +20,9 @@
|
|||||||
{-# LANGUAGE OverloadedStrings #-}
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
import Network.Minio
|
import Network.Minio
|
||||||
|
|
||||||
import Data.Conduit (($$+-))
|
import qualified Data.Conduit as C
|
||||||
import Data.Conduit.Binary (sinkLbs)
|
import qualified Data.Conduit.Binary as CB
|
||||||
|
|
||||||
import Prelude
|
import Prelude
|
||||||
|
|
||||||
-- | The following example uses minio's play server at
|
-- | The following example uses minio's play server at
|
||||||
@ -37,8 +38,8 @@ main = do
|
|||||||
bucket = "my-bucket"
|
bucket = "my-bucket"
|
||||||
object = "my-object"
|
object = "my-object"
|
||||||
res <- runMinio minioPlayCI $ do
|
res <- runMinio minioPlayCI $ do
|
||||||
src <- getObject bucket object
|
src <- getObject bucket object def
|
||||||
(src $$+- sinkLbs)
|
C.connect src $ CB.sinkFileCautious "/tmp/my-object"
|
||||||
|
|
||||||
case res of
|
case res of
|
||||||
Left e -> putStrLn $ "getObject failed." ++ (show e)
|
Left e -> putStrLn $ "getObject failed." ++ (show e)
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
#!/usr/bin/env stack
|
#!/usr/bin/env stack
|
||||||
-- stack --resolver lts-9.1 runghc --package minio-hs
|
-- stack --resolver lts-11.1 runghc --package minio-hs
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Minio Haskell SDK, (C) 2017 Minio, Inc.
|
-- Minio Haskell SDK, (C) 2017, 2018 Minio, Inc.
|
||||||
--
|
--
|
||||||
-- Licensed under the Apache License, Version 2.0 (the "License");
|
-- Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
-- you may not use this file except in compliance with the License.
|
-- you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
-- stack --resolver lts-11.1 runghc --package minio-hs
|
-- stack --resolver lts-11.1 runghc --package minio-hs
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Minio Haskell SDK, (C) 2018 Minio, Inc.
|
-- Minio Haskell SDK, (C) 2017, 2018 Minio, Inc.
|
||||||
--
|
--
|
||||||
-- Licensed under the Apache License, Version 2.0 (the "License");
|
-- Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
-- you may not use this file except in compliance with the License.
|
-- you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
#!/usr/bin/env stack
|
#!/usr/bin/env stack
|
||||||
-- stack --resolver lts-9.1 runghc --package minio-hs
|
-- stack --resolver lts-11.1 runghc --package minio-hs
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Minio Haskell SDK, (C) 2017 Minio, Inc.
|
-- Minio Haskell SDK, (C) 2017, 2018 Minio, Inc.
|
||||||
--
|
--
|
||||||
-- Licensed under the Apache License, Version 2.0 (the "License");
|
-- Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
-- you may not use this file except in compliance with the License.
|
-- you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
#!/usr/bin/env stack
|
#!/usr/bin/env stack
|
||||||
-- stack --resolver lts-9.1 runghc --package minio-hs
|
-- stack --resolver lts-11.1 runghc --package minio-hs
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Minio Haskell SDK, (C) 2017 Minio, Inc.
|
-- Minio Haskell SDK, (C) 2017, 2018 Minio, Inc.
|
||||||
--
|
--
|
||||||
-- Licensed under the Apache License, Version 2.0 (the "License");
|
-- Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
-- you may not use this file except in compliance with the License.
|
-- you may not use this file except in compliance with the License.
|
||||||
@ -20,8 +20,7 @@
|
|||||||
{-# LANGUAGE OverloadedStrings #-}
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
import Network.Minio
|
import Network.Minio
|
||||||
|
|
||||||
import Data.Conduit (($$))
|
import Conduit
|
||||||
import Data.Conduit.Combinators (sinkList)
|
|
||||||
import Prelude
|
import Prelude
|
||||||
|
|
||||||
-- | The following example uses minio's play server at
|
-- | The following example uses minio's play server at
|
||||||
@ -39,7 +38,7 @@ main = do
|
|||||||
-- Performs a recursive listing of incomplete uploads under bucket "test"
|
-- Performs a recursive listing of incomplete uploads under bucket "test"
|
||||||
-- on a local minio server.
|
-- on a local minio server.
|
||||||
res <- runMinio minioPlayCI $
|
res <- runMinio minioPlayCI $
|
||||||
listIncompleteUploads bucket Nothing True $$ sinkList
|
runConduit $ listIncompleteUploads bucket Nothing True .| mapM_C (\v -> (liftIO $ print v))
|
||||||
print res
|
print res
|
||||||
|
|
||||||
{-
|
{-
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
#!/usr/bin/env stack
|
#!/usr/bin/env stack
|
||||||
-- stack --resolver lts-9.1 runghc --package minio-hs
|
-- stack --resolver lts-11.1 runghc --package minio-hs
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Minio Haskell SDK, (C) 2017 Minio, Inc.
|
-- Minio Haskell SDK, (C) 2017, 2018 Minio, Inc.
|
||||||
--
|
--
|
||||||
-- Licensed under the Apache License, Version 2.0 (the "License");
|
-- Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
-- you may not use this file except in compliance with the License.
|
-- you may not use this file except in compliance with the License.
|
||||||
@ -20,8 +20,7 @@
|
|||||||
{-# LANGUAGE OverloadedStrings #-}
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
import Network.Minio
|
import Network.Minio
|
||||||
|
|
||||||
import qualified Data.Conduit as C
|
import Conduit
|
||||||
import qualified Data.Conduit.Combinators as CC
|
|
||||||
import Prelude
|
import Prelude
|
||||||
|
|
||||||
|
|
||||||
@ -40,9 +39,8 @@ main = do
|
|||||||
-- Performs a recursive listing of all objects under bucket "test"
|
-- Performs a recursive listing of all objects under bucket "test"
|
||||||
-- on play.minio.io.
|
-- on play.minio.io.
|
||||||
res <- runMinio minioPlayCI $
|
res <- runMinio minioPlayCI $
|
||||||
listObjects bucket Nothing True C.$$ CC.sinkList
|
runConduit $ listObjects bucket Nothing True .| mapM_C (\v -> (liftIO $ print v))
|
||||||
print res
|
print res
|
||||||
|
|
||||||
{-
|
{-
|
||||||
Following is the output of the above program on a local Minio server.
|
Following is the output of the above program on a local Minio server.
|
||||||
|
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
#!/usr/bin/env stack
|
#!/usr/bin/env stack
|
||||||
-- stack --resolver lts-9.1 runghc --package minio-hs
|
-- stack --resolver lts-11.1 runghc --package minio-hs
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Minio Haskell SDK, (C) 2017 Minio, Inc.
|
-- Minio Haskell SDK, (C) 2017, 2018 Minio, Inc.
|
||||||
--
|
--
|
||||||
-- Licensed under the Apache License, Version 2.0 (the "License");
|
-- Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
-- you may not use this file except in compliance with the License.
|
-- you may not use this file except in compliance with the License.
|
||||||
@ -32,8 +32,7 @@ import Prelude
|
|||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = do
|
||||||
let
|
let bucket = "my-bucket"
|
||||||
bucket = "my-bucket"
|
|
||||||
res <- runMinio minioPlayCI $
|
res <- runMinio minioPlayCI $
|
||||||
-- N B the region provided for makeBucket is optional.
|
-- N B the region provided for makeBucket is optional.
|
||||||
makeBucket bucket (Just "us-east-1")
|
makeBucket bucket (Just "us-east-1")
|
||||||
@ -1,8 +1,8 @@
|
|||||||
#!/usr/bin/env stack
|
#!/usr/bin/env stack
|
||||||
-- stack --resolver lts-9.1 runghc --package minio-hs
|
-- stack --resolver lts-11.1 runghc --package minio-hs
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Minio Haskell SDK, (C) 2017 Minio, Inc.
|
-- Minio Haskell SDK, (C) 2017, 2018 Minio, Inc.
|
||||||
--
|
--
|
||||||
-- Licensed under the Apache License, Version 2.0 (the "License");
|
-- Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
-- you may not use this file except in compliance with the License.
|
-- you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
#!/usr/bin/env stack
|
#!/usr/bin/env stack
|
||||||
-- stack --resolver lts-9.1 runghc --package minio-hs
|
-- stack --resolver lts-11.1 runghc --package minio-hs
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Minio Haskell SDK, (C) 2017 Minio, Inc.
|
-- Minio Haskell SDK, (C) 2017, 2018 Minio, Inc.
|
||||||
--
|
--
|
||||||
-- Licensed under the Apache License, Version 2.0 (the "License");
|
-- Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
-- you may not use this file except in compliance with the License.
|
-- you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
#!/usr/bin/env stack
|
#!/usr/bin/env stack
|
||||||
-- stack --resolver lts-9.1 runghc --package minio-hs
|
-- stack --resolver lts-11.1 runghc --package minio-hs
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Minio Haskell SDK, (C) 2017 Minio, Inc.
|
-- Minio Haskell SDK, (C) 2017, 2018 Minio, Inc.
|
||||||
--
|
--
|
||||||
-- Licensed under the Apache License, Version 2.0 (the "License");
|
-- Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
-- you may not use this file except in compliance with the License.
|
-- you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
#!/usr/bin/env stack
|
#!/usr/bin/env stack
|
||||||
-- stack --resolver lts-9.1 runghc --package minio-hs
|
-- stack --resolver lts-11.1 runghc --package minio-hs
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Minio Haskell SDK, (C) 2017 Minio, Inc.
|
-- Minio Haskell SDK, (C) 2017, 2018 Minio, Inc.
|
||||||
--
|
--
|
||||||
-- Licensed under the Apache License, Version 2.0 (the "License");
|
-- Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
-- you may not use this file except in compliance with the License.
|
-- you may not use this file except in compliance with the License.
|
||||||
@ -22,6 +22,8 @@ import Network.Minio
|
|||||||
|
|
||||||
import qualified Data.Conduit.Combinators as CC
|
import qualified Data.Conduit.Combinators as CC
|
||||||
|
|
||||||
|
import Prelude
|
||||||
|
|
||||||
-- | The following example uses minio's play server at
|
-- | The following example uses minio's play server at
|
||||||
-- https://play.minio.io:9000. The endpoint and associated
|
-- https://play.minio.io:9000. The endpoint and associated
|
||||||
-- credentials are provided via the libary constant,
|
-- credentials are provided via the libary constant,
|
||||||
@ -44,7 +46,6 @@ main = do
|
|||||||
Left e -> putStrLn $ "putObject failed." ++ show e
|
Left e -> putStrLn $ "putObject failed." ++ show e
|
||||||
Right () -> putStrLn "putObject succeeded."
|
Right () -> putStrLn "putObject succeeded."
|
||||||
|
|
||||||
|
|
||||||
-- Eg 2. Upload a file using fPutObject with default options.
|
-- Eg 2. Upload a file using fPutObject with default options.
|
||||||
res2 <- runMinio minioPlayCI $
|
res2 <- runMinio minioPlayCI $
|
||||||
fPutObject bucket object localFile def
|
fPutObject bucket object localFile def
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
#!/usr/bin/env stack
|
#!/usr/bin/env stack
|
||||||
-- stack --resolver lts-9.1 runghc --package minio-hs
|
-- stack --resolver lts-11.1 runghc --package minio-hs
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Minio Haskell SDK, (C) 2017 Minio, Inc.
|
-- Minio Haskell SDK, (C) 2017, 2018 Minio, Inc.
|
||||||
--
|
--
|
||||||
-- Licensed under the Apache License, Version 2.0 (the "License");
|
-- Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
-- you may not use this file except in compliance with the License.
|
-- you may not use this file except in compliance with the License.
|
||||||
@ -1,8 +1,8 @@
|
|||||||
#!/usr/bin/env stack
|
#!/usr/bin/env stack
|
||||||
-- stack --resolver lts-9.1 runghc --package minio-hs
|
-- stack --resolver lts-11.1 runghc --package minio-hs
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Minio Haskell SDK, (C) 2017 Minio, Inc.
|
-- Minio Haskell SDK, (C) 2017, 2018 Minio, Inc.
|
||||||
--
|
--
|
||||||
-- Licensed under the Apache License, Version 2.0 (the "License");
|
-- Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
-- you may not use this file except in compliance with the License.
|
-- you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
#!/usr/bin/env stack
|
#!/usr/bin/env stack
|
||||||
-- stack --resolver lts-9.1 runghc --package minio-hs
|
-- stack --resolver lts-11.1 runghc --package minio-hs
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Minio Haskell SDK, (C) 2017 Minio, Inc.
|
-- Minio Haskell SDK, (C) 2017, 2018 Minio, Inc.
|
||||||
--
|
--
|
||||||
-- Licensed under the Apache License, Version 2.0 (the "License");
|
-- Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
-- you may not use this file except in compliance with the License.
|
-- you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
-- stack --resolver lts-11.1 runghc --package minio-hs
|
-- stack --resolver lts-11.1 runghc --package minio-hs
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Minio Haskell SDK, (C) 2018 Minio, Inc.
|
-- Minio Haskell SDK, (C) 2017, 2018 Minio, Inc.
|
||||||
--
|
--
|
||||||
-- Licensed under the Apache License, Version 2.0 (the "License");
|
-- Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
-- you may not use this file except in compliance with the License.
|
-- you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
-- stack --resolver lts-11.1 runghc --package minio-hs
|
-- stack --resolver lts-11.1 runghc --package minio-hs
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Minio Haskell SDK, (C) 2018 Minio, Inc.
|
-- Minio Haskell SDK, (C) 2017, 2018 Minio, Inc.
|
||||||
--
|
--
|
||||||
-- Licensed under the Apache License, Version 2.0 (the "License");
|
-- Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
-- you may not use this file except in compliance with the License.
|
-- you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@ -38,5 +38,5 @@ instance FromJSON AdminErrJSON where
|
|||||||
parseErrResponseJSON :: (MonadIO m) => LByteString -> m ServiceErr
|
parseErrResponseJSON :: (MonadIO m) => LByteString -> m ServiceErr
|
||||||
parseErrResponseJSON jsondata =
|
parseErrResponseJSON jsondata =
|
||||||
case eitherDecode jsondata of
|
case eitherDecode jsondata of
|
||||||
Right (AdminErrJSON code message) -> return $ toServiceErr code message
|
Right aErr -> return $ toServiceErr (aeCode aErr) (aeMessage aErr)
|
||||||
Left err -> throwIO $ MErrVJsonParse $ T.pack err
|
Left err -> throwIO $ MErrVJsonParse $ T.pack err
|
||||||
|
|||||||
@ -22,6 +22,7 @@ module Network.Minio.PutObject
|
|||||||
) where
|
) where
|
||||||
|
|
||||||
|
|
||||||
|
import Conduit (takeC)
|
||||||
import qualified Data.ByteString.Lazy as LBS
|
import qualified Data.ByteString.Lazy as LBS
|
||||||
import qualified Data.Conduit as C
|
import qualified Data.Conduit as C
|
||||||
import qualified Data.Conduit.Binary as CB
|
import qualified Data.Conduit.Binary as CB
|
||||||
@ -68,7 +69,7 @@ putObjectInternal b o opts (ODStream src sizeMay) = do
|
|||||||
-- got file size, so check for single/multipart upload
|
-- got file size, so check for single/multipart upload
|
||||||
Just size ->
|
Just size ->
|
||||||
if | size <= 64 * oneMiB -> do
|
if | size <= 64 * oneMiB -> do
|
||||||
bs <- C.runConduit $ src C..| CB.sinkLbs
|
bs <- C.runConduit $ src C..| takeC (fromIntegral size) C..| CB.sinkLbs
|
||||||
putObjectSingle' b o (pooToHeaders opts) $ LBS.toStrict bs
|
putObjectSingle' b o (pooToHeaders opts) $ LBS.toStrict bs
|
||||||
| size > maxObjectSize -> throwIO $ MErrVPutSizeExceeded size
|
| size > maxObjectSize -> throwIO $ MErrVPutSizeExceeded size
|
||||||
| otherwise -> sequentialMultipartUpload b o opts (Just size) src
|
| otherwise -> sequentialMultipartUpload b o opts (Just size) src
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user