Attaching Files using cURL
You can attach files to CouchDB just like email. The file contains metadata like name and includes its MIME type, and the number of bytes the attachment contains. To attach files to a document you have to send PUT request to the server. Following is the syntax to attach files to the document ā
$ curl -vX PUT http://127.0.0.1:5984/database_name/database_id /filename?rev=document rev_id --data-binary @filename -H "Content-Type: type of the content"
The request has various options that are explained below.
- –data-binary@ ā This option tells cURL to read a fileās contents into the HTTP request body.
- -H ā This option is used to mention the content type of the file we are going to upload.
Example
Let us attach a file named boy.jpg, to the document with id 001, in the database named my_database by sending PUT request to CouchDB. Before that, you have to fetch the data of the document with id 001 to get its current rev id as shown below.
$ curl -X GET http://127.0.0.1:5984/my_database/001 { "_id": "001", "_rev": "1-967a00dff5e02add41819138abb3284d" }
Now using the _rev value, send the PUT request to the CouchDB server as shown below.
$ curl -vX PUT http://127.0.0.1:5984/my_database/001/boy.jpg?rev=1- 967a00dff5e02add41819138abb3284d --data-binary @boy.jpg -H "ContentType: image/jpg"
Verification
To verify whether the attachment is uploaded, fetch the document content as shown belowā
$ curl -X GET http://127.0.0.1:5984/my_database/001 { "_id": "001", "_rev": "2-4705a219cdcca7c72aac4f623f5c46a8", "_attachments": { "boy.jpg": { "content_type": "image/jpg", "revpos": 2, "digest": "md5-9Swz8jvmga5mfBIsmCxCtQ==", "length": 91408, "stub": true } } }
Attaching Files using Futon
Upload Attachment
Using this option, you can upload a new attachment such as a file, image, or document, to the database. To do so, click on theĀ Upload AttachmentĀ button. A dialog box will appear where you can choose the file to be uploaded. Select the file and click on theĀ UploadĀ button.
The file uploaded will be displayed under _attachments field. Later you can see the file by clicking on it.
I think this is one of the most significant info for
me. And i’m glad reading your article. But should remark on few general things,
The website style is perfect, the articles is really
great : D. Good job, cheers
Thanks..
In this category
you can play animal and wild bird truck games and learn how to become a wild animal transporter driver
Keep in mind that at certain levels of the Jurassic Wildlife Safari Transfer game
Pingback: Homepage
Pingback: University of Central Lancashire