Chunk Upload scenario: Cannot

1 Answer 137 Views
Upload
DoomerDGR8
Top achievements
Rank 2
Iron
Iron
Iron
DoomerDGR8 asked on 13 Aug 2022, 02:54 PM

I'm not using Newtosoft.Json anymore so I tried to deserialize the metadata like this:

var chunkData = JsonSerializer.Deserialize<ChunkMetaDataModel>(metaData)!;

It's not getting de-serialized properly as all strings are null and all integers are 0s.

Please update this documentation page: ASP.NET Core Upload Component Chunk Upload | Telerik UI for ASP.NET Core & this demo: Chunk Upload in ASP.NET Core Upload Component Demo | Telerik UI for ASP.NET Core soon as I'm stuck for now.

I originally got help from StackOverflow from my question: c# - System.Text.Json.* & deserialization of streams - Stack Overflow

1 Answer, 1 is accepted

Sort by
1
Mihaela
Telerik team
answered on 17 Aug 2022, 04:44 PM

Hi Hassan,

By default, the System.Text.Json deserialization looks for case-sensitive property name matches between JSON and the target object properties. The "metaData" JSON is Camel case-formatted, so it cannot be deserialized correctly:

To change that behavior, set JsonSerializerOptions.PropertyNameCaseInsensitive to true, as is stated in the documentation:

https://docs.microsoft.com/en-us/dotnet/standard/serialization/system-text-json-character-casing#case-insensitive-property-matching

For example:

using System.Text.Json;

public async Task<ActionResult> Chunk_Upload_Save(IEnumerable<IFormFile> files, string metaData)
{
            if (metaData == null)
            {
                return await Save(files);
            }

            ChunkMetaDataModel chunkData;
            var options = new JsonSerializerOptions
            {
                PropertyNameCaseInsensitive = true
            };
            chunkData = JsonSerializer.Deserialize<ChunkMetaDataModel>(metaData, options);

            ...
}

I hope that helps.

 

Regards, Mihaela Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
Upload
Asked by
DoomerDGR8
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Mihaela
Telerik team
Share this question
or