2011-11-17 3 views

답변

3

당연히 파일 업로드는 HTTP POST입니다. 이제 HTTP/1.1 POST with Ibrowse을 수행하는 Erlang 코드를 먼저 작성하십시오.

 
%% Assumes Ibrowse application is in Code path 
ensure_ibrowse()-> 
    case whereis(ibrowse) of 
     undefined -> ibrowse:start(); 
     _ -> ok 
    end.
post(Link,Data,Headers)-> ensure_ibrowse(), try ibrowse:send_req(Link,Headers,post,Data) of { _, _, _,Result} -> io:format("\n\tFile Uploaded. Return: ~p~n",[Result]); EE -> {error,EE} catch XX:XX2 -> {error,XX,XX2} end.

여기에서 우리의 소파 DB를 할 수 있습니다.

 
-define(Link,"http://localhost:5984/DBNAME/DOCID/Penguins?rev=LATEST_REVISION").
%% File_path must be a valid file ! upload_file(Full_file_path)-> case file:read_file(Full_file_path) of {ok,Binary} -> post(?Link,Binary,[{"Content-Type","image/jpeg"}]); Error -> Error end.

저기! 매크로 Link을 사용자의 소파 DB 설정에 맞게 사용자 정의하면됩니다.

+1

파일이 크면 청크로 보내야 할 수도 있습니다.이 경우 헤더에는 다음과 비슷한 내용이 포함됩니다.'{ "Content-Type", "multipart/form-data"}' –

관련 문제