Autodesk forge 인증에 문제가 있습니다. 가끔 전화 할 때 401을받습니다 oss/v2/buckets/{key}/objects/{object}
. 이것은 드물게 발생하지만 언급 할 가치가있는 것은 두 개의 다른 클라이언트에서 두 개의 동일한 파일을 동시에 업로드하려고 할 때 복제 할 수 있었던 한 가지 방법입니다.
이 시나리오는 일반적으로 작동, 또는 인용 브라이언 Fantana을 -
매번 작동하는 시간의 60 %.
이 문제를 어떻게 해결합니까? 몇 가지 지침이 매우 도움이 될 것입니다.
미리 감사드립니다.
이 문제를 스스로 해결했다는 소식을 듣게되어 기쁩니다. 업로드 할 때마다 토큰을 새로 고치면 이제이 문제가 해결 될 수 있지만 buckets/:bucketKey/objects/:objectName/resumable
큰 파일을 청크로 업로드하는 데 사용 하는 것이 좋습니다 .
대용량 파일의 경우 공식 문서 에서 청크라고하는 여러 개의 작은 부분으로 분리 하여 buckets/:bucketKey/objects/:objectName/resumable
API로 업로드하는 것이 좋습니다. 다음은 동료가 제공 한이 API 용 Forge C # SDK 의 C # 샘플입니다 .
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);
}
이 도움을 바랍니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다