on 6cda3fa help sign in
44 lines 1.3 kB history raw
1{-# LANGUAGE OverloadedStrings #-}
2{-# LANGUAGE ScopedTypeVariables #-}
4-- |
5-- Module : Example.Storage
6-- Copyright : (c) 2015-2016 Brendan Hay
7-- License : Mozilla Public License, v. 2.0.
8-- Maintainer : Brendan Hay <brendan.g.hay@gmail.com>
9-- Stability : provisional
10-- Portability : non-portable (GHC extensions)
11--
12module Example.Storage where
14import Control.Lens ((&), (.~), (<&>), (?~))
15import Data.Text (Text)
16import Network.Google
17import Network.Google.Storage
18import System.IO (stdout)
20import qualified Data.Text as Text
22-- This will calculate the MIME type (and therefore Content-Type) of
23-- the stored object based on the file extension.
24--
25-- You can explicitly set the desired MIME type by using:
26-- {-
27-- import Network.HTTP.Media ((//))
28----
29-- b <- sourceBody f <&> bodyContentType .~ "application" // "json"
30-- ...
31--
32-- -}
33example :: Text -> FilePath -> IO ()
34example bkt f = do
35 l <- newLogger Debug stdout
36 e <- newEnv <&> (envLogger .~ l) . (envScopes .~ storageReadWriteScope)
37 b <- sourceBody f
39 let key = Text.pack f
41 runResourceT . runGoogle e $ do
42 _ <- upload (objectsInsert bkt object' & oiName ?~ key) b
43 _ <- download (objectsGet bkt key)
44 pure ()