I have run into trouble when trying to use streaming package for AWS S3
requests. The trouble seems to be that the API in question (`AWS.pureAws
<http://haddock.stackage.org/lts-6.2/aws-0.13.2/Aws.html#g:3>`) returns a
type `ResourceT IO a` while the streaming package provides `ResourceT m a`.
I couldn't locate any documentation on how to do the lift to convert
between two types. My code is below - I get the error `No instance for
(SP.MonadResource IO) arising from a use of ‘Q.readFile’`.
{-# 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.
--
You received this message because you are subscribed to the Google Groups
"Haskell Pipes" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].