Kaynağa Gözat

Quick fix and todo

master
radivoje.milutinovic 3 yıl önce
ebeveyn
işleme
0ac6340b1e

+ 2
- 2
SecureSharing.Business/Services/MessageService.cs Dosyayı Görüntüle



private void DeleteFiles(Guid basePathGuid) private void DeleteFiles(Guid basePathGuid)
{ {
// var basePath = Path.Combine(_webHostEnvironment.WebRootPath.Split('/')[0], DefaultPath, message.Code.ToString());
var basePath = $"C:\\Users\\radivoje.milutinovic\\Downloads\\fajlovitmp\\{basePathGuid.ToString()}";
// TODO: this path needs to be extracted somehow.
var basePath = Path.Combine(@"D:\secure-sharing\SecureSharing\wwwroot\files", basePathGuid.ToString());
Directory.Delete(basePath, true); Directory.Delete(basePath, true);
} }

+ 5
- 8
SecureSharing/Controllers/HomeController.cs Dosyayı Görüntüle

using System.Text.Json;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.StaticFiles; using Microsoft.AspNetCore.StaticFiles;
using SecureSharing.Business.Dtos; using SecureSharing.Business.Dtos;
var message = new MessageDto { Text = model.Text }; var message = new MessageDto { Text = model.Text };
var basePath = Path.Combine(_webHostEnvironment.WebRootPath.Split('/')[0], DefaultPath, message.Code.ToString()); var basePath = Path.Combine(_webHostEnvironment.WebRootPath.Split('/')[0], DefaultPath, message.Code.ToString());
// var basePath = $"C:\\Users\\radivoje.milutinovic\\Downloads\\fajlovitmp\\{message.Code}";
Directory.CreateDirectory(basePath); Directory.CreateDirectory(basePath);
foreach (var formFile in model.Files) foreach (var formFile in model.Files)
{ {
if (formFile.Length <= 0) continue;
// Console.WriteLine(JsonSerializer.Serialize(formFile));
if (formFile.Length <= 0)
continue;
var filePath = Path.Combine(basePath, formFile.FileName); var filePath = Path.Combine(basePath, formFile.FileName);
await using var stream = new FileStream(filePath, FileMode.Create, FileAccess.ReadWrite); await using var stream = new FileStream(filePath, FileMode.Create, FileAccess.ReadWrite);
await formFile.CopyToAsync(stream); await formFile.CopyToAsync(stream);
await using var stream = new FileStream(path, FileMode.Open); await using var stream = new FileStream(path, FileMode.Open);
await stream.CopyToAsync(memory); await stream.CopyToAsync(memory);
memory.Position = 0; memory.Position = 0;
string? contentType;
new FileExtensionContentTypeProvider().TryGetContentType(filename, out contentType);
new FileExtensionContentTypeProvider().TryGetContentType(filename, out var contentType);
return contentType is null ? null : File(memory, contentType,Path.GetFileName(path)); return contentType is null ? null : File(memory, contentType,Path.GetFileName(path));
// Response.Redirect();
} }


[HttpGet] [HttpGet]

Loading…
İptal
Kaydet