Пример #1
0
        protected Uri GetFinishUriForThreadedUploads()
        {
            var finishUri = new StringBuilder(string.Format("{0}&respformat=json", UploadSpecification.FinishUri.AbsoluteUri));

            if (File.Length > 0)
            {
                HashProvider.Finalize(new byte[1], 0, 0);
                finishUri.AppendFormat("&filehash={0}", HashProvider.GetComputedHashAsString());
            }

            if (!string.IsNullOrEmpty(UploadSpecificationRequest.Details))
            {
                finishUri.AppendFormat("&details={0}", Uri.EscapeDataString(UploadSpecificationRequest.Details));
            }
            if (!string.IsNullOrEmpty(UploadSpecificationRequest.Title))
            {
                finishUri.AppendFormat("&title={0}", Uri.EscapeDataString(UploadSpecificationRequest.Title));
            }
            if (UploadSpecificationRequest.ForceUnique)
            {
                finishUri.Append("&forceunique=1");
            }

            return(new Uri(finishUri.ToString()));
        }
        private async Task <UploadResponse> FinishUpload(CancellationToken cancellationToken)
        {
            HashProvider.Finalize(new byte[0], 0, 0);
            var finishUri      = GetFinishUriForThreadedUploads();
            var requestMessage = new HttpRequestMessage(HttpMethod.Get, finishUri);

            var responseMessage = await SendHttpRequest(requestMessage, cancellationToken).ConfigureAwait(false);

            string localHash      = HashProvider.GetComputedHashAsString();
            var    uploadResponse = await GetUploadResponseAsync(responseMessage, localHash).ConfigureAwait(false);

            if (uploadResponse.Count == 1)
            {
                string serverHash = uploadResponse.Single().Hash;
                if (!string.IsNullOrEmpty(serverHash) && !localHash.Equals(serverHash, StringComparison.OrdinalIgnoreCase))
                {
                    throw new UploadException($"File hash mismatch! Client: {localHash} Server: {serverHash}", Enums.UploadStatusCode.Unknown);
                }
            }

            return(uploadResponse);
        }