Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes Bad Request on Attachment Upload #164

Merged
merged 1 commit into from
May 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/CouchDB.Driver/Converters/AttachmentsParsedConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using CouchDB.Driver.Types;
using Newtonsoft.Json;

namespace CouchDB.Driver.Converters
{
internal class AttachmentsParsedConverter : JsonConverter<Dictionary<string, CouchAttachment>>
{
public override void WriteJson(JsonWriter writer, Dictionary<string, CouchAttachment> value,
JsonSerializer serializer)
{
serializer.Serialize(writer, value
.Where(kvp => kvp.Value.FileInfo is null)
.ToDictionary(k => k.Key, v => v.Value)
);
}

public override bool CanRead => false;

public override Dictionary<string, CouchAttachment> ReadJson(JsonReader reader, Type objectType,
Dictionary<string, CouchAttachment> existingValue, bool hasExistingValue,
JsonSerializer serializer)
{
throw new NotImplementedException();
}
}
}
2 changes: 2 additions & 0 deletions src/CouchDB.Driver/Types/CouchDocument.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#nullable disable
using System.Collections.Generic;
using System.Runtime.Serialization;
using CouchDB.Driver.Converters;
using Newtonsoft.Json;

namespace CouchDB.Driver.Types
Expand Down Expand Up @@ -47,6 +48,7 @@ protected CouchDocument()
// This must be for serialization only field
[DataMember]
[JsonProperty("_attachments", NullValueHandling = NullValueHandling.Ignore)]
[JsonConverter(typeof(AttachmentsParsedConverter))]
private Dictionary<string, CouchAttachment> AttachmentsParsed { get; set; }

[JsonIgnore]
Expand Down