2012-02-24 2 views

답변

2

에서

덕분에 CouchDB attachments 문서를 읽기 시작합니다. 예를 들어

:

  • 문서 my_doc에서

    • 콘텐츠 Hello, world

    으로 파일 hello.html

  • 를 연결하는 방법은 64 기수와 컨텐츠를 인코딩합니다. "Hello world""'SGVsbG8gd29ybGQ="입니다.

    는 그리고 당신은이 같은 문서를 만들 :

    { "_id": "my_doc", 
    , "_attachments": 
        { "hello.html": 
        { "content_type": "text/html" 
        , "data": "'SGVsbG8gd29ybGQ=" 
        } 
        } 
    } 
    

    유일한 어려운 부분은 base64 인코딩이다. CouchDB에 포함 된 base64 스크립트를 사용하는 것이 좋습니다.

    <html> 
        <head> 
        <script src="/_utils/script/base64.js"></script> 
        </head> 
        <body> 
        The Base64 of "Hello world" is: 
        <script> 
        var hello = "Hello world" 
        var encoded = Base64.encode(hello) 
        document.write(encoded) 
        </script> 
    
        <p> 
    
        A document with this attachment is:<br> 
        <script> 
        var doc = { "_id":"my_doc" } 
    
        doc._attachments = {} 
        doc._attachments["hello.html"] = {} 
        doc._attachments["hello.html"].content_type = "text/html" 
        doc._attachments["hello.html"].data = Base64.encode("Hello world") 
    
        document.write(JSON.stringify(doc))  
        </script> 
        </body> 
    </html> 
    
  • 관련 문제