2017-05-23 13 views
0

autodesk forge 인증에 문제가 있습니다. 때로는 oss/v2/buckets/{key}/objects/{object}으로 전화 할 때 401을받습니다. 이것은 드물게 발생하지만 언급할만한 점은 두 개의 서로 다른 클라이언트에서 동시에 두 개의 동일한 파일을 업로드하려고 할 때 한 번 복제 할 수 있다는 것입니다.파일을 동시에 업로드 할 때 autodesk forge 인증 문제

이 시나리오는 일반적으로 작동, 또는 브라이언 Fantana 인용 - 그것은 모든 시간을 작동 시간의

60 %.

이 문제를 어떻게 해결할 수 있습니까? 어떤 지침은 매우 도움이 될 것입니다.

미리 감사드립니다.

+0

파일에 대해이 API 호출에 소요되는 시간은 얼마나됩니까? 30 분 이상 걸리면 사용한 토큰이 만료되기 전에 새로 고쳐야합니다. –

+0

답장을 보내 주셔서 감사합니다. 파일 크기는 155MB 였고 aprox를 사용했습니다. 업로드 2 분. 동시에 업로드 할 때 Autodesk의 종료에는 제한이 있습니까? –

+0

나를 위해 Forge 버킷에 업로드 된 파일의 총 크기를 확인할 수 있습니까? 내 경험에 따르면, api'oss/v2/buckets/{key}/objects/{object}'로 20MB보다 큰 파일을 업로드하는 데 실패 할 것입니다. –

답변

1

직접이 문제를 해결하는 것이 좋다고 들었습니다. 모든 업로드에서 토큰을 새로 고침하면이 문제가 해결 될 수 있지만 큰 파일을 청크로 업로드하려면 buckets/:bucketKey/objects/:objectName/resumable을 사용하는 것이 좋습니다.

대용량 파일의 경우 공식 document에 청크라는 작은 부품으로 분리하여 buckets/:bucketKey/objects/:objectName/resumable API로 업로드하는 것이 좋습니다.

private static dynamic resumableUploadFile() 
{ 
    Console.WriteLine("*****Start uploading file to the OSS"); 
    string path = FILE_PATH; 
    if (!File.Exists(path)) 
     path = @"..\..\..\" + FILE_PATH; 

    //File Total size   
    long fileSize = new System.IO.FileInfo(path).Length; 
    //Chunk size for separting file into several parts. 
    //2MB chuck size is used in this sample. 
    long chunkSize = 2 * 1024 * 1024 ; 
    //Total amounts of chunks in 2MB size. 
    long nbChunks = (long)Math.Round(0.5 + (double)fileSize/(double)chunkSize); 

    ApiResponse<dynamic> finalRes = null ; 
    using (FileStream streamReader = new FileStream(path, FileMode.Open)) 
    { 
    //Unique id for resumable uploading. 
    string sessionId = RandomString(12); 
    for (int i = 0; i < nbChunks; i++) 
    { 
     //Start position in bytes of a chunk 
     long start = i * chunkSize; 
     //End position in bytes of a chunk 
     //(End posistion of the latest chuck is the total file size in bytes) 
     long end = Math.Min(fileSize, (i + 1) * chunkSize) - 1; 

     //Identify chunk info. to the Forge 
     string range = "bytes " + start + "-" + end + "/" + fileSize; 
     //Steam size for this chunk 
     long length = end - start + 1; 

     Console.WriteLine("Uploading range: " + range); 

     //Read content stream into a meomery stream for this chunk 
     byte[] buffer = new byte[length]; 
     MemoryStream memoryStream = new MemoryStream(buffer); 

     int nb = streamReader.Read(buffer, 0, (int)length); 
     memoryStream.Write(buffer, 0, nb); 
     memoryStream.Position = 0; 

     //Upload file to the Forge OSS Bucket 
     ApiResponse<dynamic> response = objectsApi.UploadChunk(
              BUCKET_KEY, 
              FILE_NAME, 
              (int)length, 
              range, 
              sessionId, 
              memoryStream 
             ); 

     finalRes = response; 

     if (response.StatusCode == 202) { 
      Console.WriteLine("One chunk uploaded successfully"); 
      continue; 
     } 
     else if (response.StatusCode == 200) 
     { 
      Console.WriteLine("Final chunk uploaded successfully"); 
     } 
     else 
     { 
      //Some error occurred here 
      Console.WriteLine(response.StatusCode); 
      break; 
     } 
    } 

    } 

    return (finalRes); 
} 

희망이 도움말 : 여기 내 동료에서이 API에 대한 the Forge C# SDK의 C#을 샘플입니다.

+0

이 솔루션을 제공해 주셔서 감사합니다. 구현되었으며 잘 작동하는 것 같습니다. 이것을 정답으로 추가하겠습니다. –

0

이 문제를 해결하기 위해 항상 업로드 할 때마다 토큰의 만료 시간을 변경해야했습니다.