コード例 #1
0
        IRestRequest IRequestBuilder.PutCompleteFileUpload(string uploadPath, ApiCompleteFileUpload completeParams)
        {
            RestRequest request = new RestRequest(uploadPath, Method.PUT);

            SetGeneralRestValues(request, true, completeParams);
            return(request);
        }
コード例 #2
0
        IRestRequest IRequestBuilder.PutCompleteS3FileUpload(string uploadId, ApiCompleteFileUpload completeParams)
        {
            RestRequest request = new RestRequest(ApiConfig.ApiPutCompleteS3Upload, Method.PUT);

            SetGeneralRestValues(request, true, completeParams);
            request.AddUrlSegment("uploadId", uploadId);
            return(request);
        }
コード例 #3
0
        internal static ApiCompleteFileUpload ToApiCompleteFileUpload(FileUploadRequest fileUploadRequest)
        {
            ApiCompleteFileUpload apiCompleteFileUpload = new ApiCompleteFileUpload {
                FileName           = fileUploadRequest.Name,
                ResolutionStrategy = EnumConverter.ConvertResolutionStrategyToValue(fileUploadRequest.ResolutionStrategy)
            };

            return(apiCompleteFileUpload);
        }
コード例 #4
0
        protected override Node StartUpload()
        {
            NotifyStarted(ActionId);
            ApiCreateFileUpload apiFileUploadRequest = FileMapper.ToApiCreateFileUpload(FileUploadRequest);

            try {
                apiFileUploadRequest.UseS3 = CheckUseS3();
            } catch (DracoonApiException apiException) {
                DracoonClient.Log.Warn(LogTag, "S3 direct upload is not possible.", apiException);
            }

            IRestRequest uploadTokenRequest = Client.Builder.PostCreateFileUpload(apiFileUploadRequest);

            UploadToken = Client.Executor.DoSyncApiCall <ApiUploadToken>(uploadTokenRequest, RequestType.PostUploadToken);

            Node                  publicResultNode;
            PlainFileKey          plainFileKey          = CreateFileKey();
            ApiCompleteFileUpload apiCompleteFileUpload = FileMapper.ToApiCompleteFileUpload(FileUploadRequest);

            if (apiFileUploadRequest.UseS3.HasValue && apiFileUploadRequest.UseS3.Value)
            {
                List <ApiS3FileUploadPart> s3Parts          = EncryptedS3Upload(ref plainFileKey);
                EncryptedFileKey           encryptedFileKey = EncryptFileKey(plainFileKey);
                apiCompleteFileUpload.FileKey = FileMapper.ToApiFileKey(encryptedFileKey);
                apiCompleteFileUpload.Parts   = s3Parts;
                IRestRequest completeFileUploadRequest = Client.Builder.PutCompleteS3FileUpload(UploadToken.UploadId, apiCompleteFileUpload);
                Client.Executor.DoSyncApiCall <VoidResponse>(completeFileUploadRequest, RequestType.PutCompleteS3Upload);
                publicResultNode = NodeMapper.FromApiNode(S3Finished());
            }
            else
            {
                EncryptedUpload(ref plainFileKey);
                EncryptedFileKey encryptedFileKey = EncryptFileKey(plainFileKey);
                apiCompleteFileUpload.FileKey = FileMapper.ToApiFileKey(encryptedFileKey);
                IRestRequest completeFileUploadRequest =
                    Client.Builder.PutCompleteFileUpload(new Uri(UploadToken.UploadUrl).PathAndQuery, apiCompleteFileUpload);
                ApiNode resultNode = Client.Executor.DoSyncApiCall <ApiNode>(completeFileUploadRequest, RequestType.PutCompleteUpload);
                publicResultNode = NodeMapper.FromApiNode(resultNode);
            }

            NotifyFinished(ActionId, publicResultNode);
            return(publicResultNode);
        }
コード例 #5
0
        public void ToApiCompleteFileUpload()
        {
            // ARRANGE
            ResolutionStrategy paramStrategy    = ResolutionStrategy.Overwrite;
            string             expectedStrategy = "overwrite";

            ApiCompleteFileUpload expected = FactoryFile.ApiCompleteFileUpload;

            expected.FileKey            = null;
            expected.ResolutionStrategy = expectedStrategy;

            FileUploadRequest param = new FileUploadRequest(63534, expected.FileName)
            {
                ResolutionStrategy = paramStrategy
            };

            Mock.Arrange(() => EnumConverter.ConvertResolutionStrategyToValue(paramStrategy)).Returns(expectedStrategy);

            // ACT
            ApiCompleteFileUpload actual = FileMapper.ToApiCompleteFileUpload(param);

            // ASSERT
            Assert.Equal(expected, actual, new ApiCompleteFileUploadComparer());
        }