Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ cabal.sandbox.config
*.eventlog
.stack-work/
cabal.project.local
*~
*~
tags
tags.mtime
17 changes: 17 additions & 0 deletions src/Network/Minio.hs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ module Network.Minio

-- ** Conduit-based streaming operations
putObject,
putObjectStream,
PutObjectOptions,
defaultPutObjectOptions,
pooContentType,
Expand All @@ -151,6 +152,7 @@ module Network.Minio
pooUserMetadata,
pooNumThreads,
pooSSE,
pooIfNoneMatch,
getObject,
GetObjectOptions,
defaultGetObjectOptions,
Expand Down Expand Up @@ -284,6 +286,21 @@ putObject ::
putObject bucket object src sizeMay opts =
void $ putObjectInternal bucket object opts $ ODStream src sizeMay

-- | Put an object from a conduit source. The size need be provided.
-- This version of putting object is optimized to stream data without
-- need to be full resident in memory and then this is suitable
-- to put small objects cause it is never does multipart upload
putObjectStream ::
Bucket ->
Object ->
C.ConduitM () ByteString Minio () ->
Int64 ->
MinioConn ->
PutObjectOptions ->
Minio ()
putObjectStream bucket object src size minioConn opts =
void $ putObjectInternalStream bucket object opts src size minioConn

-- | Perform a server-side copy operation to create an object based on
-- the destination specification in DestinationInfo from the source
-- specification in SourceInfo. This function performs a multipart
Expand Down
12 changes: 8 additions & 4 deletions src/Network/Minio/Data.hs
Original file line number Diff line number Diff line change
Expand Up @@ -373,12 +373,14 @@ data PutObjectOptions = PutObjectOptions
-- | Set number of worker threads used to upload an object.
pooNumThreads :: Maybe Word,
-- | Set object encryption parameters for the request.
pooSSE :: Maybe SSE
pooSSE :: Maybe SSE,
-- | Set a behavior to put object with name already existed in storage.
pooIfNoneMatch :: Maybe Text
}

-- | Provide default `PutObjectOptions`.
defaultPutObjectOptions :: PutObjectOptions
defaultPutObjectOptions = PutObjectOptions Nothing Nothing Nothing Nothing Nothing Nothing [] Nothing Nothing
defaultPutObjectOptions = PutObjectOptions Nothing Nothing Nothing Nothing Nothing Nothing [] Nothing Nothing Nothing

pooToHeaders :: PutObjectOptions -> [HT.Header]
pooToHeaders poo =
Expand All @@ -395,7 +397,8 @@ pooToHeaders poo =
"content-disposition",
"content-language",
"cache-control",
"x-amz-storage-class"
"x-amz-storage-class",
"if-none-match"
]
values =
map
Expand All @@ -405,7 +408,8 @@ pooToHeaders poo =
pooContentDisposition,
pooContentLanguage,
pooCacheControl,
pooStorageClass
pooStorageClass,
pooIfNoneMatch
]

-- |
Expand Down
13 changes: 13 additions & 0 deletions src/Network/Minio/PutObject.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

module Network.Minio.PutObject
( putObjectInternal,
putObjectInternalStream,
ObjectData (..),
selectPartSizes,
)
Expand Down Expand Up @@ -103,6 +104,18 @@ putObjectInternal b o opts (ODFile fp sizeMay) = do
sequentialMultipartUpload b o opts (Just size) $
CB.sourceFile fp

-- | Put an object from ObjectData, optimized to put streamly
putObjectInternalStream ::
Bucket ->
Object ->
PutObjectOptions ->
C.ConduitM () ByteString Minio () ->
Int64 ->
MinioConn ->
Minio ETag
putObjectInternalStream b o opts src size minioConn = do
putObjectSingleStream b o (pooToHeaders opts) src size minioConn

parallelMultipartUpload ::
Bucket ->
Object ->
Expand Down
39 changes: 39 additions & 0 deletions src/Network/Minio/S3API.hs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ module Network.Minio.S3API
maxSinglePutObjectSizeBytes,
putObjectSingle',
putObjectSingle,
putObjectSingleStream,
copyObjectSingle,

-- * Multipart Upload APIs
Expand Down Expand Up @@ -108,6 +109,7 @@ module Network.Minio.S3API
where

import qualified Data.ByteString as BS
import qualified Conduit as C
import qualified Data.Text as T
import Lib.Prelude
import qualified Network.HTTP.Conduit as NC
Expand Down Expand Up @@ -229,6 +231,43 @@ putObjectSingle' bucket object headers bs = do
return
etag


-- | PUT an object into the service. This function performs a single
-- PUT object call and uses a conduit of ByteString as the object
-- data.
putObjectSingleStream ::
Bucket ->
Object ->
[HT.Header] ->
C.ConduitM () ByteString Minio () ->
Int64 ->
MinioConn ->
Minio ETag
putObjectSingleStream bucket object headers src size minioConn = do
when (size > maxSinglePutObjectSizeBytes) $
throwIO $
MErrVSinglePUTSizeExceeded size

let payload = PayloadC size $ C.transPipe (flip runReaderT minioConn . coerce) src
resp <-
mkStreamRequest $
defaultS3ReqInfo
{ riMethod = HT.methodPut,
riBucket = Just bucket,
riObject = Just object,
riHeaders = headers,
riPayload = payload
}

let rheaders = NC.responseHeaders resp
etag = getETagHeader rheaders
maybe
(throwIO MErrVETagHeaderNotFound)
return
etag



-- | PUT an object into the service. This function performs a single
-- PUT object call, and so can only transfer objects upto 5GiB.
putObjectSingle ::
Expand Down