CSV ファイルをアップロードして、最終的に DB に格納されるテーブルに解析しようとしています。私は Yesod のファイル アップロードの例をいじっていましたが、Yesod の最新バージョンでは動作しないようです。を使用してYesod 1.2.5.2 and GHC 7.6.3 on Ubuntu 14.04
います。
以下は私のコードです
fileUploadForm :: Form ((Key Account), FileInfo)
fileUploadForm = renderDivs $ (,)
<$> areq (selectField accounts) "Account" Nothing
<*> fileAFormReq "Choose a file"
where
accounts = do
entities <- runDB $ selectList [] [Asc AccountName]
optionsPairs $ map (\s -> (accountName $ entityVal s, entityKey s)) entities
getUploadTransactionR :: Handler Html
getUploadTransactionR = do
(widget, enctype) <- generateFormPost fileUploadForm
defaultLayout $ do
setTitle "Upload new file."
$(widgetFile "upload_transactions")
これは私があなたの助けを求めたい部分です:
postUploadTransactionR :: Handler Html
postUploadTransactionR = do
((result, widget), enctype) <- runFormPost fileUploadForm
case result of
FormSuccess (account, fi) -> do
-- ??? I would like to get the contents of fi and send it to a CSV parser.
-- (fileSourceRaw fi)???
redirect (HomeR)
_ -> return ()
defaultLayout $ do
$(widgetFile "upload_transactions")
ByteString を取得したら、Data.Csv を使用して次のように解析します。decode NoHeader s :: Either String (Vector (Vector ByteString))
アップロードされたファイルからファイルの内容を取得する方法を誰かに教えてもらえますか? ファイルをディスクに保存する必要はありません。
ありがとう!