Skip to content

Commit 1d473dc

Browse files
committed
fix
1 parent 39fb34b commit 1d473dc

6 files changed

Lines changed: 28 additions & 22 deletions

File tree

ManagedCode.Storage.Client/IStorageClient.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace ManagedCode.Storage.Client;
99

1010
public interface IStorageClient
1111
{
12+
void SetChunkSize(long size);
1213
Task<Result<BlobMetadata>> UploadFile(Stream stream, string apiUrl, string contentName, CancellationToken cancellationToken = default);
1314
Task<Result<BlobMetadata>> UploadFile(FileInfo fileInfo, string apiUrl, string contentName, CancellationToken cancellationToken = default);
1415
Task<Result<BlobMetadata>> UploadFile(byte[] bytes, string apiUrl, string contentName, CancellationToken cancellationToken = default);

ManagedCode.Storage.Client/ManagedCode.Storage.Client.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
<ItemGroup>
2222
<ProjectReference Include="..\ManagedCode.Storage.Core\ManagedCode.Storage.Core.csproj" />
23-
<ProjectReference Include="..\ManagedCode.Storage.Server\ManagedCode.Storage.Server.csproj" />
2423
</ItemGroup>
2524

2625
<ItemGroup>

ManagedCode.Storage.Client/StorageClient.cs

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,41 @@
99
using System.Threading;
1010
using System.Threading.Tasks;
1111
using ManagedCode.Communication;
12-
using ManagedCode.Storage.Core.Helpers;
1312
using ManagedCode.Storage.Core.Models;
14-
using ManagedCode.Storage.Server;
15-
using Microsoft.Extensions.Configuration;
1613

1714
namespace ManagedCode.Storage.Client;
1815

1916
public class StorageClient : IStorageClient
2017
{
2118
private readonly HttpClient _httpClient;
22-
private readonly IConfiguration _configuration;
23-
24-
public StorageClient(HttpClient httpClient, IConfiguration configuration)
19+
private long _chunkSize;
20+
21+
public StorageClient(HttpClient httpClient)
2522
{
2623
_httpClient = httpClient;
27-
_configuration = configuration;
2824
}
2925

26+
public long ChunkSize
27+
{
28+
get
29+
{
30+
if (_chunkSize == null)
31+
{
32+
throw new NullReferenceException("ChunkSize doesn't set");
33+
}
34+
return _chunkSize;
35+
}
36+
set
37+
{
38+
_chunkSize = value;
39+
}
40+
}
41+
42+
public void SetChunkSize(long size)
43+
{
44+
ChunkSize = size;
45+
}
46+
3047
public async Task<Result<BlobMetadata>> UploadFile(Stream stream, string apiUrl, string contentName, CancellationToken cancellationToken = default)
3148
{
3249
var streamContent = new StreamContent(stream);
@@ -135,10 +152,9 @@ public async Task<Result<uint>> UploadLargeFile(Stream file,
135152
Action<double>? onProgressChanged,
136153
CancellationToken cancellationToken = default)
137154
{
138-
int bufferSize = Int32.Parse(_configuration.GetSection("ChunkSize").Value);
155+
long bufferSize = ChunkSize;
139156
var buffer = new byte[bufferSize];
140157
int chunkIndex = 1;
141-
uint fileCRC = 123214;
142158
var partOfProgress = file.Length / bufferSize;
143159
var fileName = "file" + Guid.NewGuid();
144160

@@ -157,7 +173,6 @@ public async Task<Result<uint>> UploadLargeFile(Stream file,
157173
formData.Add(content, "File", fileName);
158174
formData.Add(new StringContent(chunkIndex.ToString()), "Payload.ChunkIndex");
159175
formData.Add(new StringContent(bufferSize.ToString()), "Payload.ChunkSize");
160-
formData.Add(new StringContent(fileCRC.ToString()), "Payload.FullCRC");
161176
await _httpClient.PostAsync(uploadApiUrl, formData, cancellationToken);
162177
}
163178
}

ManagedCode.Storage.IntegrationTests/Tests/BaseControllerTests.cs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,6 @@ protected HttpClient GetHttpClient()
2323

2424
protected IStorageClient GetStorageClient()
2525
{
26-
var myConfiguration = new Dictionary<string, string>
27-
{
28-
{"ChunkSize", "4096000"}
29-
};
30-
31-
var configuration = new ConfigurationBuilder()
32-
.AddInMemoryCollection(myConfiguration)
33-
.Build();
34-
35-
return new StorageClient(TestApplication.CreateClient(), configuration);
26+
return new StorageClient(TestApplication.CreateClient());
3627
}
3728
}

ManagedCode.Storage.IntegrationTests/Tests/BaseUploadControllerTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ public async Task UploadLargeFile_WhenFileValid_ReturnSuccess()
124124
await using var localFile = LocalFile.FromRandomNameWithExtension(".txt");
125125
FileHelper.GenerateLocalFile(localFile, 750);
126126
var crc32 = Crc32Helper.Calculate(await localFile.ReadAllBytesAsync());
127+
storageClient.SetChunkSize(4096000);
127128

128129
// Act
129130
var result = await storageClient.UploadLargeFile(localFile.FileStream,

ManagedCode.Storage.Server/FileUploadPayload.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,4 @@ public class FilePayload
1212
{
1313
public int ChunkIndex { get; set; }
1414
public int ChunkSize { get; set; }
15-
public uint FullCRC { get; set; }
1615
}

0 commit comments

Comments
 (0)