Beispiel #1
0
        public async Task <Guid> UploadAsync(IFileProxy file)
        {
            using (var fileStream = file.OpenRead())
            {
                using (fileStream)
                {
                    var result = await _httpClient.PostAsync(_options.EndpointUrl, new StreamContent(fileStream)
                    {
                        Headers =
                        {
                            ContentDisposition =
                            {
                                FileName = file.FileName,
                                Name     = nameof(file),
                                Size     = file.Size,
                            }
                        }
                    });

                    result.EnsureSuccessStatusCode();

                    var resultContent = await result.Content.ReadAsStringAsync();

                    return(Guid.Parse(resultContent));
                }
            }
        }
Beispiel #2
0
        public Task <Guid> UploadAsync(IFileProxy file)
        {
            var uuid = Guid.NewGuid();

            using (var inputStream = file.OpenRead())
            {
                var storedFilePath = GetFilePath(uuid);
                using (var outputStream = File.Create(storedFilePath))
                {
                    inputStream.CopyTo(outputStream);
                }
            }

            return(Task.FromResult(uuid));
        }