{"action":"created","issue":{"url":"https://api.github.com/repos/yesodweb/yesod/issues/961","labels_url":"https://api.github.com/repos/yesodweb/yesod/issues/961/labels{/name}","comments_url":"https://api.github.com/repos/yesodweb/yesod/issues/961/comments","events_url":"https://api.github.com/repos/yesodweb/yesod/issues/961/events","html_url":"https://github.com/yesodweb/yesod/issues/961","id":63630047,"number":961,"title":"Uploading a file ","user":{"login":"MonrealRyan","id":8383129,"avatar_url":"https://avatars.githubusercontent.com/u/8383129?v=3","gravatar_id":"","url":"https://api.github.com/users/MonrealRyan","html_url":"https://github.com/MonrealRyan","followers_url":"https://api.github.com/users/MonrealRyan/followers","following_url":"https://api.github.com/users/MonrealRyan/following{/other_user}","gists_url":"https://api.github.com/users/MonrealRyan/gists{/gist_id}","starred_url":"https://api.github.com/users/MonrealRyan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MonrealRyan/subscriptions","organizations_url":"https://api.github.com/users/MonrealRyan/orgs","repos_url":"https://api.github.com/users/MonrealRyan/repos","events_url":"https://api.github.com/users/MonrealRyan/events{/privacy}","received_events_url":"https://api.github.com/users/MonrealRyan/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":23,"created_at":"2015-03-23T05:38:55Z","updated_at":"2015-03-24T10:55:54Z","closed_at":null,"body":"Hi, \r\nI was having a hard time on uploading a file to my ``static`` folder.\r\n\r\nhere is my code hope you help me.\r\n\r\n```\r\n{-# LANGUAGE MultiParamTypeClasses #-}\r\n{-# LANGUAGE OverloadedStrings #-}\r\n{-# LANGUAGE QuasiQuotes #-}\r\n{-# LANGUAGE TemplateHaskell #-}\r\n{-# LANGUAGE TypeFamilies #-}\r\n\r\nmodule FileServer where\r\n\r\nimport Yesod\r\nimport Yesod.Static\r\nimport Data.Time (UTCTime)\r\nimport System.FilePath\r\nimport System.Directory (removeFile, doesFileExist)\r\nimport Control.Applicative ((<$>), (<*>))\r\nimport Data.Conduit\r\nimport Data.Text (unpack)\r\nimport qualified Data.ByteString.Lazy as DBL\r\nimport Data.Conduit.List (consume)\r\n\r\n--import some libraries\r\nimport Data.Default\r\nimport Text.Hamlet\r\nimport Yesod.Default.Util\r\n\r\nimport Control.Exception hiding (Handler)\r\nimport qualified Data.ByteString.Lazy as LB\r\nimport Data.Default\r\nimport Data.Text (Text)\r\nimport qualified Data.Text as Text\r\nimport qualified Data.Text.Lazy as LT\r\nimport qualified Data.Text.Lazy.Encoding as LT\r\nimport Text.Blaze\r\n\r\n\r\n\r\nstaticFiles \"static\"\r\n\r\ndata App = App\r\n    {\r\n        getStatic :: Static\r\n    }\r\n\r\nmkYesod \"App\" [parseRoutes|\r\n/ HomeR GET POST\r\n/static StaticR Static getStatic\r\n|]\r\n\r\ninstance Yesod App where\r\n  defaultLayout widget = do\r\n    pc <- widgetToPageContent $ $(widgetFileNoReload def \"default-layout\")\r\n    withUrlRenderer $(hamletFile \"templates/default-layout-wrapper.hamlet\")\r\n\r\ninstance RenderMessage App FormMessage where\r\n    renderMessage _ _ = defaultFormMessage\r\n\r\n\r\nuploadForm = renderDivs $ fileAFormReq \"file\"\r\n\r\nuploadDirectory :: FilePath\r\nuploadDirectory = \"static\"\r\n\r\ngetHomeR :: Handler Html\r\ngetHomeR = do\r\n    (formWidget, formEncType) <- generateFormPost uploadForm\r\n    mmsg <- getMessage\r\n    defaultLayout $ do\r\n        setTitle \"File Processor\"\r\n        $(widgetFileNoReload def \"home\")\r\n\r\npostHomeR :: Handler Html\r\npostHomeR = do\r\n    ((result, widget), enctype) <- runFormPost uploadForm\r\n    case result of\r\n        FormSuccess (file) -> do\r\n            -- TODO: check if image already exists\r\n            -- save to image directory\r\n            filename <- writeToServer file\r\n            setMessage $ toMarkup $ \"Image saved = \" `Text.append` \"Image Name\"\r\n            redirect HomeR\r\n        _ -> do\r\n            setMessage \"Something went wrong\"\r\n            redirect HomeR\r\n\r\nwriteToServer :: FileInfo -> Handler FilePath\r\nwriteToServer file = do\r\n    let filename = unpack $ fileName file\r\n        path = imageFilePath filename\r\n    liftIO $ fileMove file path\r\n    return filename\r\n\r\nimageFilePath :: String -> FilePath\r\nimageFilePath f = uploadDirectory </> f\r\n\r\nmain :: IO ()\r\nmain = do\r\n    static@(Static settings) <- static \"static\"\r\n    warpEnv $ App static\r\n```\r\nthe file was not seen on the ``static`` folder also there's no error so i'm confuse where does my file goes.\r\n\r\nhope you help me."},"comment":{"url":"https://api.github.com/repos/yesodweb/yesod/issues/comments/85449418","html_url":"https://github.com/yesodweb/yesod/issues/961#issuecomment-85449418","issue_url":"https://api.github.com/repos/yesodweb/yesod/issues/961","id":85449418,"user":{"login":"geraldus","id":744471,"avatar_url":"https://avatars.githubusercontent.com/u/744471?v=3","gravatar_id":"","url":"https://api.github.com/users/geraldus","html_url":"https://github.com/geraldus","followers_url":"https://api.github.com/users/geraldus/followers","following_url":"https://api.github.com/users/geraldus/following{/other_user}","gists_url":"https://api.github.com/users/geraldus/gists{/gist_id}","starred_url":"https://api.github.com/users/geraldus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/geraldus/subscriptions","organizations_url":"https://api.github.com/users/geraldus/orgs","repos_url":"https://api.github.com/users/geraldus/repos","events_url":"https://api.github.com/users/geraldus/events{/privacy}","received_events_url":"https://api.github.com/users/geraldus/received_events","type":"User","site_admin":false},"created_at":"2015-03-24T10:55:54Z","updated_at":"2015-03-24T10:55:54Z","body":"Oh, sorry for so many stupid noise! There **must** be `enctype` attribute specified in form:\r\n\r\n``` htmk\r\n<form method=post enctype=#{formEncType}>\r\n   ^{formWidget}\r\n   <input type=submit>\r\n```\r\n\r\nAnd everything should work."}}