Open neozhu opened 4 months ago
internal static async Task<T?> HttpPatchAsync<T>(this PocketBase pocketBase, string url, T item)
where T : ItemBase
{
var body = JsonSerializer.Deserialize<Dictionary<string, object>>(JsonSerializer.Serialize(item));
var files = item.RelatedFiles.Where(f => f != null && f.HasChanges)?.Select(f => f!.GetSdkFileToUpload()).Where(f => f != null).Select(f => f!)?.ToList();
if (files?.Any() ?? false)
{
await pocketBase.SendAsync<T>(url, HttpMethod.Patch, files: files);
}
// remove FieldFileBase field for fix The field contains unknown filenames.
foreach (var property in typeof(T).GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static)
.Where(prop => prop.PropertyType.IsSubclassOf(typeof(FieldFileBase))))
{
var jsonPropertyNameAttribute = property.GetCustomAttribute<JsonPropertyNameAttribute>();
if (jsonPropertyNameAttribute is not null)
{
body.Remove(jsonPropertyNameAttribute.Name);
}
}
var result = await pocketBase.SendAsync<T>(url, HttpMethod.Patch, body: body);
return result;
}
'{"code":400,"message":"Failed to load the submitted data due to invalid formatting.","data":{"avatar":{"code":"validation_unknown_filenames","message":"The field contains unknown filenames."}}} '