on ecf0dd4 help sign in
32 lines 991 B history raw
1{-# LANGUAGE OverloadedStrings #-}
3-- |
4-- Module : Example.Storage
5-- Copyright : (c) 2015-2016 Brendan Hay
6-- License : Mozilla Public License, v. 2.0.
7-- Maintainer : Brendan Hay <brendan.g.hay@gmail.com>
8-- Stability : provisional
9-- Portability : non-portable (GHC extensions)
10--
11module Example.Storage where
13import Control.Lens
14import Data.Text (Text)
15import qualified Data.Text as Text
16import Network.Google
17import Network.Google.Storage
18import System.IO
20example :: Text -> FilePath -> IO ()
21example bkt f = do
22 l <- newLogger Debug stdout
23 e <- newEnv <&> (envLogger .~ l) . allow devstorageReadWriteScope
24 b <- sourceBody f
26 let key = Text.pack f
27 obj = object' & objContentType ?~ "application/octet-stream"
29 runResourceT . runGoogle e $ do
30 _ <- upload (objectsInsert bkt obj & oiName ?~ key) b
31 _ <- download (objectsGet bkt key)
32 pure ()