createAttachment method
Create an attachment on an existing document. contentType is in the form of a mime type e.g. 'image/png' If the document needs to be created as well as the attachment set the rev to ''.
Implementation
Future<dynamic> createAttachment(String? docId, String? attachmentName,
String? rev, String? contentType, String? payload) {
// Check all parameters are supplied
if (docId == null) {
return _raiseException(WiltException.createAttNoDocId);
}
if (attachmentName == null) {
return _raiseException(WiltException.createAttNoName);
}
if (rev == null) {
return _raiseException(WiltException.createAttNoRev);
}
if (contentType == null) {
return _raiseException(WiltException.createAttNoContentType);
}
if (payload == null) {
return _raiseException(WiltException.createAttNoPayload);
}
// Set the headers
final headers = <String, String>{};
headers['Content-Type'] = contentType;
// Make the PUT request
String url;
if (rev != '') {
url = '$docId/$attachmentName?rev=$rev';
} else {
url = '$docId/$attachmentName';
}
url = _conditionUrl(url);
return _httpRequest(createAttachmentt, url,
data: payload, headers: headers);
}