File: MultipartTransfer.hs

package info (click to toggle)
haskell-aws 0.24.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 868 kB
  • sloc: haskell: 9,593; makefile: 2
file content (37 lines) | stat: -rw-r--r-- 1,578 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
{-# LANGUAGE OverloadedStrings #-}

{- This example demonstrates an ability to stream in constant space content from a remote resource into an S3 object accessible publicly -}


import qualified Aws
import           Aws.Aws              (Configuration (..))
import qualified Aws.S3               as S3
import           Control.Applicative  ((<$>))
import           Control.Monad.Trans.Resource
import qualified Data.Text            as T
import           Network.HTTP.Conduit (http, parseUrl, responseBody,
                                       newManager, tlsManagerSettings)
import           System.Environment   (getArgs)

main :: IO ()
main = do
  maybeCreds <- Aws.loadCredentialsFromEnv
  case maybeCreds of
    Nothing -> do
      putStrLn "Please set the environment variables AWS_ACCESS_KEY_ID and AWS_ACCESS_KEY_SECRET"
    Just creds -> do
      args <- getArgs
      cfg <- Aws.dbgConfiguration
      let s3cfg = Aws.defServiceConfig :: S3.S3Configuration Aws.NormalQuery

      case args of
        [sourceUrl,destBucket,destObj] -> do
          request <- parseUrl sourceUrl
	  mgr <- newManager tlsManagerSettings
          runResourceT $ do
            source <- responseBody <$> http request mgr
            let initiator b o = (S3.postInitiateMultipartUpload b o){S3.imuAcl = Just S3.AclPublicRead}
            S3.multipartUploadWithInitiator cfg{credentials = creds} s3cfg initiator mgr (T.pack destBucket) (T.pack destObj) source (10*1024*1024)
        _ -> do
          putStrLn "Usage: MultipartTransfer sourceUrl destinationBucket destinationObjectname"