diff --git a/src/Gargantext/Components/Forest/Tree/Node/Action/Upload.purs b/src/Gargantext/Components/Forest/Tree/Node/Action/Upload.purs index bcc8116387bfc564e63c1edd8269d85fcec52c67..53af80be7e4e6ab6e43c035648840bf4b1b53209 100644 --- a/src/Gargantext/Components/Forest/Tree/Node/Action/Upload.purs +++ b/src/Gargantext/Components/Forest/Tree/Node/Action/Upload.purs @@ -3,7 +3,7 @@ module Gargantext.Components.Forest.Tree.Node.Action.Upload where import Prelude (class Show, Unit, const, discard, map, pure, show, ($), (<>), bind, void) import Data.Maybe (Maybe(..), fromJust) import Data.Newtype (class Newtype) -import Data.Tuple (Tuple) +import Data.Tuple (Tuple(..)) import Data.Tuple.Nested ((/\)) import Effect.Aff (Aff, launchAff) import Effect.Class (liftEffect) @@ -169,8 +169,12 @@ instance fileUploadQueryToQuery :: ToQuery FileUploadQuery where uploadFile :: Session -> ID -> FileType -> UploadFileContents -> Aff AsyncTask uploadFile session id fileType (UploadFileContents fileContents) = - postWwwUrlencoded session p fileContents + postWwwUrlencoded session p bodyParams --postMultipartFormData session p fileContents where q = FileUploadQuery { fileType: fileType } - p = NodeAPI Corpus (Just id) $ "add/form/async" <> Q.print (toQuery q) + p = NodeAPI Corpus (Just id) $ "add/file/async" <> Q.print (toQuery q) + bodyParams = [ + Tuple "_wf_data" (Just fileContents) + , Tuple "_wf_filetype" (Just $ show fileType) + ] diff --git a/src/Gargantext/Config/REST.purs b/src/Gargantext/Config/REST.purs index fa7f2fd25873ea27addac641ed2a9548593a1c5e..fd3da1cd4f4dff05bac8d7cbb3d185a6b55c565c 100644 --- a/src/Gargantext/Config/REST.purs +++ b/src/Gargantext/Config/REST.purs @@ -69,9 +69,11 @@ deleteWithBody mtoken url = send DELETE mtoken url <<< Just post :: forall a b. EncodeJson a => DecodeJson b => Maybe Token -> String -> a -> Aff b post mtoken url = send POST mtoken url <<< Just +type FormDataParams = Array (Tuple String (Maybe String)) + -- TODO too much duplicate code with `send` -postWwwUrlencoded :: forall b. DecodeJson b => Maybe Token -> String -> String -> Aff b -postWwwUrlencoded mtoken url body = do +postWwwUrlencoded :: forall b. DecodeJson b => Maybe Token -> String -> FormDataParams -> Aff b +postWwwUrlencoded mtoken url bodyParams = do affResp <- request $ defaultRequest { url = url , responseFormat = ResponseFormat.json @@ -96,7 +98,7 @@ postWwwUrlencoded mtoken url body = do Left err -> throwError $ error $ "decodeJson affResp.body: " <> err Right b -> pure b where - urlEncodedBody = FormURLEncoded.fromArray [Tuple "body" (Just body)] + urlEncodedBody = FormURLEncoded.fromArray bodyParams postMultipartFormData :: forall b. DecodeJson b => Maybe Token -> String -> String -> Aff b postMultipartFormData mtoken url body = do diff --git a/src/Gargantext/Sessions.purs b/src/Gargantext/Sessions.purs index 5627b9e9620deacdbecf5c0fe7bc9b738096f950..84c3e06343108bd1acd0827ee912f149f570ac9b 100644 --- a/src/Gargantext/Sessions.purs +++ b/src/Gargantext/Sessions.purs @@ -223,7 +223,7 @@ deleteWithBody session@(Session {token}) p = REST.deleteWithBody (Just token) (t post :: forall a b p. EncodeJson a => DecodeJson b => ToUrl Session p => Session -> p -> a -> Aff b post session@(Session {token}) p = REST.post (Just token) (toUrl session p) -postWwwUrlencoded :: forall b p. DecodeJson b => ToUrl Session p => Session -> p -> String -> Aff b +postWwwUrlencoded :: forall b p. DecodeJson b => ToUrl Session p => Session -> p -> REST.FormDataParams -> Aff b postWwwUrlencoded session@(Session {token}) p = REST.postWwwUrlencoded (Just token) (toUrl session p) postMultipartFormData :: forall b p. DecodeJson b => ToUrl Session p => Session -> p -> String -> Aff b