Skip to content

Commit 5653642

Browse files
authored
Merge pull request #2 from dhirensham/feature/submit-attachments-inline-with-document-body
Submit attachments inline in the document body, instead of adding sep…
2 parents 59bbe20 + ca16e44 commit 5653642

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

src/CouchDB.Driver/CouchDatabase.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,21 @@ public async Task<TSource> AddOrUpdateAsync(TSource document, AddOrUpdateOptions
295295
if (options.Rev != null)
296296
request = request.SetQueryParam("rev", options.Rev);
297297

298+
if (document.Attachments != null && document.Attachments.Any())
299+
{
300+
document.AttachmentsParsed = document.Attachments.ToDictionary(x => x.Name, x =>
301+
{
302+
var data = new byte[x.Stream.Length];
303+
x.Stream.Read(data, 0, data.Length);
304+
305+
return new CouchAttachment()
306+
{
307+
ContentType = x.ContentType,
308+
Data = Convert.ToBase64String(data)
309+
};
310+
});
311+
}
312+
298313
document.SplitDiscriminator = _discriminator;
299314
DocumentSaveResponse response = await request
300315
.PutJsonAsync(document, cancellationToken)
@@ -303,8 +318,8 @@ public async Task<TSource> AddOrUpdateAsync(TSource document, AddOrUpdateOptions
303318
.ConfigureAwait(false);
304319
document.ProcessSaveResponse(response);
305320

306-
await UpdateAttachments(document, cancellationToken)
307-
.ConfigureAwait(false);
321+
//await UpdateAttachments(document, cancellationToken)
322+
// .ConfigureAwait(false);
308323

309324
return document;
310325
}

src/CouchDB.Driver/Types/CouchAttachment.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public sealed class CouchAttachment
100100
/// </remarks>
101101
[DataMember]
102102
[JsonProperty("data")]
103-
public string Data { get; private set; }
103+
public string Data { get; internal set; }
104104
}
105105
}
106106
#nullable restore

src/CouchDB.Driver/Types/CouchDocument.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ protected CouchDocument()
105105

106106
[DataMember, JsonProperty("_attachments", NullValueHandling = NullValueHandling.Ignore)]
107107
[JsonConverter(typeof(AttachmentsParsedConverter))]
108-
private Dictionary<string, CouchAttachment> AttachmentsParsed { get; set; }
108+
internal Dictionary<string, CouchAttachment> AttachmentsParsed { get; set; }
109109

110110
/// <summary>
111111
/// Used for database splitting

0 commit comments

Comments
 (0)