2015-01-13 33 views
4

我使用Erlang的在靈藥httpc像鳳凰一樣的應用程序內 :httpc.request(:post, {url, headers, content_type, body},[],[])嘗試和圖像發佈到API,到目前爲止,我創建的身體像藥劑:如何發佈圖像API

{:ok, data} = File.read(image.path) body = "{ \"param\": \"value\", \"file\": #{data}}"我不知道我錯了什麼,但請求與文件參數

我的問題是什麼是這樣做的靈丹妙藥的方式?

+4

你可以嘗試使用[HTTPoison](https://github.com/edgurgel/httpoison),這可能是更藥劑-γ。具體來說,你會得到什麼錯誤? – whatyouhide

+1

看看這個問題的答案:http://stackoverflow.com/questions/27134219/how-to-upload-a-big-file-from-a-form-to-phoenix –

+1

感謝您的評論傢伙。我最終與erlcloud一起上傳到S3這很容易 –

回答

0

如前所述上面我用erlcloud上傳到AWS 確保導出AWS鍵按的入門 鳳凰mix.exs的DEP添加

{:erlcloud,github上:「gleber/erlcloud」 }

示例代碼

def create(conn, params) do image = params["image"] image_url = to_char_list(image.filename}) {:ok, data} = File.read(image.path) :ssl.start() :erlcloud.start() :erlcloud_s3.put_object(__FOLDER__, image_url, file,[],[]) end

+0

在函數調用中,不應該是數據,而不是文件? – LucasA