代码之家  ›  专栏  ›  技术社区  ›  iElectric

使用Amazonka和Servant从S3 bucket流媒体

  •  6
  • iElectric  · 技术社区  · 8 年前

    我希望能够通过Servant作为响应主体来流式传输S3 bucket对象内容。

    我在获取处理程序缺少的MonadResource实例时遇到问题:

    src/Servant/Streaming/Example.hs:29:3: error:
        * No instance for (MonadResource Handler)
            arising from a use of `runAWS'
        * In a stmt of a 'do' block: runAWS env conduits
          In the expression:
            do env <- newEnv Discover
               runAWS env conduits
          In an equation for `server':
              server
                = do env <- newEnv Discover
                     runAWS env conduits
       |
    29 |   runAWS env conduits
       |   ^^^^^^^^^^^^^^^^^^^
    

    我制作了一个存储库来复制: https://github.com/domenkozar/servant-streaming-amazonka

    servant-streaming-server 手柄 ResourceT 对于 Stream (Of BS.ByteString) (ResourceT IO) () https://github.com/plow-technologies/servant-streaming/blob/master/servant-streaming-server/src/Servant/Streaming/Server/Internal.hs#L77-L79

    但由于我使用的是Amazonka,我还需要确保处理程序的MonadResource被放在这个括号中。我不清楚怎么做。

    我的理解是 enter / hoistServer 这将不起作用,因为资源将很快被清理(在流之前)。

    备注:

    编辑

    1. 编辑:我已经替换了 $$ 具有 $$+-
    2. EDIT2:我已经解决了特定于管道的错误,现在正在与MonadResource进行斗争
    1 回复  |  直到 8 年前
        1
  •  2
  •   iElectric    8 年前

    解决方法

    server :: Server API
    server =  do
      env <- newEnv Discover
      res <- runInternalState (runAWS env conduits) st
      return (res >> liftIO (closeInternalState st))
    

    https://github.com/domenkozar/servant-streaming-amazonka/commit/c5fad78dd7bf733cecb8790035105c819d5f5ae9

    推荐文章