2016-06-23 1 views
0

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 바이트를 포함합니다.

답변

2

Me.ItemWithPath()는/me 다음에 전체 경로가 필요합니다. 예 : _client.Me.ItemWithPath ("/ 드라이브/드라이브 아이디/항목/itemId :/파일/경로"). 이 메소드는 API를 통해 리턴 된 ItemReference에서 리턴 된 경로가 처리없이 ItemWithPath 메소드로 전달 될 수 있도록하기위한 것입니다.

당신이 사용하고자하는 것입니다 것은 :

var req = _client 
      .Me 
      .Drive 
      .ItemWithPath(path + "/" + file.Name) 
      .Content 
      .Request(); 

나 : 내가 찾은

var req = _client 
      .Me 
      .ItemWithPath(file.ParentReference.Path + "/" + file.Name) 
      .Content 
      .Request(); 
1

가에 포함 된 폴더 ID를 설정하는 리에서 경로를 건너 때때로 쉽다는 것을 SDK 문은 OneDrive 및 단일 그룹에서 작동합니다.

var createdFile = await graphClient.Me.Drive 
         .Items[currentDriveFolder.id] 
         .ItemWithPath(fileName) 
         .Content.Request() 
         .PutAsync<DriveItem>(stream); 

저는 정말 abl이되고 싶습니다. e와 같이 드라이브 ID와 폴더 ID를 설정하면됩니다.

var createdFile = await graphClient 
         .Drives[driveId] 
         .Items[folderId] 
         .ItemWithPath(fileName) 
         .Content 
         .Request() 
         .PutAsync<DriveItem>(stream); 
+0

이것은 완벽하게 작동했으며 파일을 만들고 한 번에 콘텐츠를 업로드 할 수있는 장점이있었습니다 – Sergio0694

관련 문제