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

update user avatar file get error:validation_unknown_filenames #44

Open
neozhu opened this issue May 27, 2024 · 1 comment
Open

update user avatar file get error:validation_unknown_filenames #44

neozhu opened this issue May 27, 2024 · 1 comment

Comments

@neozhu
Copy link
Collaborator

neozhu commented May 27, 2024

image
image

'{"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."}}}
'

@neozhu
Copy link
Collaborator Author

neozhu commented May 27, 2024

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;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant