{-# LANGUAGE OverloadedStrings #-}
import qualified Aws
import qualified Aws.Core as Aws
import qualified Aws.S3 as S3
import qualified Data.ByteString.Lazy as LBS
import Control.Monad.IO.Class
import System.IO
import Control.Monad.Trans.Resource (runResourceT,liftResourceT)
import Control.Concurrent.Async (async,waitCatch)
import Control.Exception (displayException)
import qualified Data.ByteString.Streaming.HTTP as SP
import qualified Data.ByteString.Streaming as Q
main :: IO ()
main = do
{- Set up AWS credentials and S3 configuration using the IA endpoint. -}
Just creds <- Aws.loadCredentialsFromEnv
let cfg = Aws.Configuration Aws.Timestamp creds (Aws.defaultLog Aws.Error)
let s3cfg = S3.s3 Aws.HTTP S3.s3EndpointUsClassic False
{- Set up a ResourceT region with an available HTTP manager. -}
httpmgr <- SP.newManager SP.tlsManagerSettings
let file ="out"
inhandle <- openFile file ReadMode
lenb <- System.IO.withFile file ReadMode hFileSize
let inbytes = Q.readFile file
runResourceT $ do
Aws.pureAws cfg s3cfg httpmgr $
(S3.putObject "put-your-test-env-here" ("testbucket/test") (SP.streamN (fromIntegral lenb) inbytes))
return ()
This seems to be the problem:
*Main> :t SP.streamN
SP.streamN :: GHC.Int.Int64 -> Q.ByteString IO () -> SP.RequestBody
*Main> :t inbytes
inbytes :: SP.MonadResource m => Q.ByteString m ()
Will appreciate pointers on how to fix this. I also can't figure out how `monadResource` and `resourceT` are related (couldn't find any good documentation about their relationship), which seems to be essential to solving the above puzzle.
(|>) = (&) -- pipe alias for readability - borrowed from Elm
-- Test function
main :: IO ()
main = do
-- oneRec pretty-prints one JSON output which we pass to putStrLn so newlines are interpreted
Q.getContents |> A.parsed oneRec |> void |> S.mapM_ BSC.putStrLn
return ()