# SyncGateway.AttachmentApi

All URIs are relative to *http://localhost:4984/*

Method | HTTP request | Description
------------- | ------------- | -------------
[**dbDocAttachmentGet**](AttachmentApi.md#dbDocAttachmentGet) | **GET** /{db}/{doc}/{attachment} | Get attachment
[**dbDocAttachmentPut**](AttachmentApi.md#dbDocAttachmentPut) | **PUT** /{db}/{doc}/{attachment} | Add or update document


<a name="dbDocAttachmentGet"></a>
# **dbDocAttachmentGet**
> &#39;String&#39; dbDocAttachmentGet(dbdocattachment, opts)

Get attachment

This request retrieves a file attachment associated with the document. The raw data of the associated attachment is returned (just as if you were accessing a static file). The Content-Type response header is the same content type set when the document attachment was added to the database. 

### Example
```javascript
var SyncGateway = require('sync_gateway');
var defaultClient = SyncGateway.ApiClient.default;

// Configure API key authorization: apiKey
var apiKey = defaultClient.authentications['apiKey'];
apiKey.apiKey = 'YOUR API KEY';
// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)
//apiKey.apiKeyPrefix = 'Token';

var apiInstance = new SyncGateway.AttachmentApi();

var db = "db_example"; // String | Database name

var doc = "doc_example"; // String | Document ID

var attachment = "attachment_example"; // String | Attachment name

var opts = { 
  'rev': "rev_example" // String | Revision identifier of the parent revision the new one should replace. (Not used when creating a new document.)
};

var callback = function(error, data, response) {
  if (error) {
    console.error(error);
  } else {
    console.log('API called successfully. Returned data: ' + data);
  }
};
apiInstance.dbDocAttachmentGet(dbdocattachment, opts, callback);
```

### Parameters

Name | Type | Description  | Notes
------------- | ------------- | ------------- | -------------
 **db** | **String**| Database name | 
 **doc** | **String**| Document ID | 
 **attachment** | **String**| Attachment name | 
 **rev** | **String**| Revision identifier of the parent revision the new one should replace. (Not used when creating a new document.) | [optional] 

### Return type

**&#39;String&#39;**

### Authorization

[apiKey](../README.md#apiKey)

### HTTP request headers

 - **Content-Type**: Not defined
 - **Accept**: application/json

<a name="dbDocAttachmentPut"></a>
# **dbDocAttachmentPut**
> Success dbDocAttachmentPut(dbdocattachment, opts)

Add or update document

This request adds or updates the supplied request content as an attachment to the specified document. The attachment name must be a URL-encoded string (the file name). You must also supply either the rev query parameter or the If-Match HTTP header for validation, and the Content-Type headers (to set the attachment content type).    When uploading an attachment using an existing attachment name, the corresponding stored content of the database will be updated. Because you must supply the revision information to add an attachment to the document, this serves as validation to update the existing attachment.    Uploading an attachment updates the corresponding document revision. Revisions are tracked for the parent document, not individual attachments. 

### Example
```javascript
var SyncGateway = require('sync_gateway');
var defaultClient = SyncGateway.ApiClient.default;

// Configure API key authorization: apiKey
var apiKey = defaultClient.authentications['apiKey'];
apiKey.apiKey = 'YOUR API KEY';
// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)
//apiKey.apiKeyPrefix = 'Token';

var apiInstance = new SyncGateway.AttachmentApi();

var db = "db_example"; // String | Database name

var doc = "doc_example"; // String | Document ID

var attachment = "attachment_example"; // String | Attachment name

var opts = { 
  'rev': "rev_example" // String | Revision identifier of the parent revision the new one should replace. (Not used when creating a new document.)
  'body': "B", // String | The request body
  'contentType': "contentType_example" // String | Attachment Content-Type
};

var callback = function(error, data, response) {
  if (error) {
    console.error(error);
  } else {
    console.log('API called successfully. Returned data: ' + data);
  }
};
apiInstance.dbDocAttachmentPut(dbdocattachment, opts, callback);
```

### Parameters

Name | Type | Description  | Notes
------------- | ------------- | ------------- | -------------
 **db** | **String**| Database name | 
 **doc** | **String**| Document ID | 
 **attachment** | **String**| Attachment name | 
 **rev** | **String**| Revision identifier of the parent revision the new one should replace. (Not used when creating a new document.) | [optional] 
 **body** | **String**| The request body | [optional] 
 **contentType** | **String**| Attachment Content-Type | [optional] 

### Return type

[**Success**](Success.md)

### Authorization

[apiKey](../README.md#apiKey)

### HTTP request headers

 - **Content-Type**: Not defined
 - **Accept**: application/json

