Microsoft Graph 용 .NET SDK를 사용하여 파일을 업로드하려고합니다. 예외가 파일의 내용을 포함하는 바이트 배열을 업로드 req.PutAsync 방법에 슬로우.NET Graph SDK - "지원되지 않는 세그먼트 형식"으로 OneDrive 파일 업로드가 실패 함
DriveItem file = new DriveItem()
{
File = new Microsoft.Graph.File(),
Name = filename,
ParentReference = new ItemReference()
{
DriveId = parent.ParentReference.DriveId,
Path = path + "/" + filename
}
};
var freq = _client
.Me
.Drive
.Items[parent.Id]
.Children
.Request();
// add the drive item
file = await freq.AddAsync(file);
DriveItem uploadedFile = null;
using (MemoryStream stream = new MemoryStream(data))
{
var req = _client
.Me
.ItemWithPath(path + "/" + file.Name)
.Content
.Request();
stream.Position = 0;
// upload the content to the driveitem just created
try
{
uploadedFile = await req.PutAsync<DriveItem>(stream);
}
catch(Exception ex)
{
Debug.WriteLine("File Put Error"); <<< FAILS HERE
}
}
return uploadedFile;
: 다음 코드이다. 나는 크기가 100 바이트 미만인 간단한 텍스트 파일로 테스트하고있다. 예외에는 잘못된 요청 및 지원되지 않는 세그먼트 유형이 포함됩니다.
파일은 OneDrive에서 만들어 지지만 0 바이트를 포함합니다.
이것은 완벽하게 작동했으며 파일을 만들고 한 번에 콘텐츠를 업로드 할 수있는 장점이있었습니다 – Sergio0694