CouchDB - SPLessons

CouchDB Attachments

Home > Lesson > Chapter 9
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

CouchDB Attachments

CouchDB Attachments

shape Description

A Database is a huge gathering of logical related  information, Which  can be  created, accessed, managed, and updated. The data may be in any form like text and numbers. There are many type of data stores, such as files on the file system, where data reading and writing will be very slow. So in this present generation, relational database administration framework is being utilized to store and maintain huge amount of information.

Attaching files into the database using Futon

shape Description

The following steps describes the process of attaching a file into the database using futon.

shape Step - 1

For attaching a file into the database open http://127.0.0.1:5984/_utils/ from the web browser.

shape Step - 2

Click on splessons1.

shape Step - 3

Click on New Document.

shape Step - 4

Click on Save Document.

shape Step - 5

Click on Upload Attachments.

shape Step - 6

Select the file and click on upload button.

shape Step - 7

The selected document as been displayed and click on source button.

shape Step - 8

It display entire file details.

Attaching files into the database using cURL Utility

shape Description

Attaching a file in couchDB database is similar to an email and these files consists of names in terms of metadata and comprises of MIME category and the numerous bytes that it attached. For attaching a file into the database can be done in CouchDB by passing a HTTP solicitation to the server utilizing PUT techniques over the utility of cURL.

shape Syntax

The syntax for attaching a file into the database using cURL utility is as follows.
$ 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"; --Data-binary@ => Read the files from the request source. -H => Describes the file content.

shape Examples

By viewing the below example,the concept of attaching a file into the database can  be easily understand. [c] $ curl -X GET http://127.0.0.1:5984/my_database/001 { "_id": "001", "_rev": "1-967a00dff5e02add41819138abb3284d" } $ 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"; $ 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 } } } [/c] Here in the above example a database by name Splessons has been successfully uploaded.

Summary

shape Key Points

  • Attaching a file into the database - Attaching a file into the database.
  • Attaching a file into the database using futon - The process of attaching a file into the database .
  • Attaching a file into the database using cURL utility - Attaching a file into the database by passing a HTTP solicitation to the server using Delete techniques.