Esempio n. 1
0
        public async Task UploadAsync(string pathFile, string pathSave, UploadProgress progress, CancellationToken cancelToken = default)
        {
            Stream stream     = new FileStream(pathFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            var    uploadLink = await GetUploadLinkAsync(pathSave);

            var fileName      = Path.GetFileName(((FileStream)stream).Name);
            var streamContent = new YandexStreamContent(stream);

            streamContent.ProgressChanged += (bytes, currBytes, totalBytes) => progress.UpdateProgress(currBytes, totalBytes, fileName);
            var content = new MultipartFormDataContent {
                { streamContent, "file", fileName }
            };

            using var yandHttpClient = new YandexHttpClient(_yandUploader.Token);
            await yandHttpClient.PostAsync(uploadLink.Href, content, cancelToken);
        }