-
Notifications
You must be signed in to change notification settings - Fork 263
Description
Hi Team,
I work on an app using the SDK and I would like to upload files from file system to SharePoint Online.
Below is part of my code:
`
BatchRequestContentCollection batch = new BatchRequestContentCollection(MSGraphService.graphClient, fileShareitems.Count());
using (FileStream fs = File.OpenRead(item.Path))
{
var fileUploadRequest = graphClient.Drives[drive.Id]
.Root
.ItemWithPath(uploadInfo[1]).Content.ToPutRequestInformation(fs);
fileUploadRequest.URI = new Uri(fileUploadRequest.URI.OriginalString + "?@microsoft.graph.conflictBehavior=rename");
var result = await batch.AddBatchRequestStepAsync(fileUploadRequest);
var returnedResponse = await MSGraphService.graphClient.Batch.PostAsync(batch);
var fileResponse = await returnedResponse.GetResponseByIdAsync<DriveItem>(result);
}
`
I expect to have my files saved to the right document library but I get the following issue:
'e' is an invalid start of a value. LineNumber: 0 | BytePositionInLine: 0.
at System.Text.Json.ThrowHelper.ThrowJsonReaderException(Utf8JsonReader& json, ExceptionResource resource, Byte nextByte, ReadOnlySpan1 bytes) at System.Text.Json.Utf8JsonReader.ConsumeValue(Byte marker) at System.Text.Json.Utf8JsonReader.ReadFirstToken(Byte first) at System.Text.Json.Utf8JsonReader.ReadSingleSegment() at System.Text.Json.Utf8JsonReader.Read() at System.Text.Json.JsonDocument.Parse(ReadOnlySpan1 utf8JsonSpan, JsonReaderOptions readerOptions, MetadataDb& database, StackRowStack& stack)
at System.Text.Json.JsonDocument.Parse(ReadOnlyMemory1 utf8Json, JsonReaderOptions readerOptions, Byte[] extraRentedArrayPoolBytes, PooledByteBufferWriter extraPooledByteBufferWriter) at System.Text.Json.JsonDocument.Parse(Stream utf8Json, JsonDocumentOptions options) at Microsoft.Kiota.Serialization.Json.JsonParseNodeFactory.GetRootParseNode(String contentType, Stream content) at Microsoft.Kiota.Abstractions.Serialization.ParseNodeProxyFactory.GetRootParseNode(String contentType, Stream content) at Microsoft.Kiota.Abstractions.Serialization.ParseNodeFactoryRegistry.GetRootParseNode(String contentType, Stream content) at Microsoft.Graph.ResponseHandler1.d__3.MoveNext()
at Microsoft.Graph.ResponseHandler1.<HandleResponseAsync>d__22.MoveNext()
at Microsoft.Graph.BatchResponseContent.d__7`1.MoveNext()
If I try to upload my files without batching by using these samples:
- https://github.com/microsoftgraph/msgraph-sdk-dotnet/blob/dev/docs/upgrade-to-v5.md#upload-a-small-file-with-conflictbehavior-set
- https://learn.microsoft.com/en-us/graph/sdks/batch-requests?tabs=csharp#simple-batching-example
It works well.
Could you please help me pointing what I am doing wrong?
My config:
- Windows 10
- Solution WinUI 3 in .NET 6.0
- MS Graph 5.22.0