ARTICLE AD BOX
I have a question about uploading files.
Currently, I am using .NET and ServiceStack framework for developing my backend. My frotend is in Angular and hosted on an IIS server. The Service Stack framework provides the feature where you can access uploaded file from the Request!.Files.
Suppose a user uploads a file of around 30 GB, and accesses it from Request!, then my flow is:
access file -> scan file for antivirus -> read file at same time store in the location and calculate md5 hash for confirming the file is the same -> if not same then clean up all the saved file.
for (int i = 0; i < Request!.Files.Length; i++) { var uploadedFile = Request.Files[i]; var metadata = request.Documents![i]; try { _logger.LogDebug("Processing file {Index}/{Total}: {FileName}", i + 1, Request.Files.Length, uploadedFile.FileName); var inputStream = uploadedFile.InputStream; var scanResult = await _antivirusScanner.ScanAsync(inputStream, uploadedFile.FileName); switch (scanResult.Status) ..... inputStream.Position = 0; } }The remainig code after that is for condtion and path creating
using var md5 = MD5.Create(); await using (var outputStream = File.Create(destination)) await using (var cryptoStream = new CryptoStream( outputStream, md5, CryptoStreamMode.Write)) { await inputStream.CopyToAsync(cryptoStream); await cryptoStream.FlushAsync(); } var computedHash = Convert.ToHexString(md5.Hash!); if (!string.Equals(computedHash, metadata.DocMd5, StringComparison.OrdinalIgnoreCase)) { // .... }My question is: I have some issues from AI reviwer if stream is not seekable, then you can get exception or the miss configuration happen. Can anyone suggest a better approach for that? Please let me know - any suggestion is helpful to me.
