|
@@ -17,41 +17,38 @@ namespace FileStorage.Host.Controllers
|
|
|
private readonly ILogger<FileController> _logger;
|
|
|
private readonly IFileStorage _fileStorage;
|
|
|
private readonly ISugarUnitOfWork<FileStorageDbContext> _uow;
|
|
|
- private readonly ISessionContext _sessionContext;
|
|
|
|
|
|
public FileController(
|
|
|
ILogger<FileController> logger,
|
|
|
IFileStorage fileStorage,
|
|
|
- ISugarUnitOfWork<FileStorageDbContext> uow,
|
|
|
- ISessionContext sessionContext
|
|
|
+ ISugarUnitOfWork<FileStorageDbContext> uow
|
|
|
)
|
|
|
{
|
|
|
_logger = logger;
|
|
|
_fileStorage = fileStorage;
|
|
|
_uow = uow;
|
|
|
- _sessionContext = sessionContext;
|
|
|
}
|
|
|
|
|
|
[HttpPost("upload")]
|
|
|
- public IActionResult Upload(IFormFile fileData)
|
|
|
+ public IActionResult Upload(UploadDto dto)
|
|
|
{
|
|
|
//var fileData = Request.Form.Files[0];
|
|
|
- var file = _fileStorage.Upload(fileData.FileName, fileData.Length, "", fileData.OpenReadStream(), _sessionContext.ClientId ?? string.Empty);
|
|
|
+ var file = _fileStorage.Upload(dto.FileData.FileName, dto.FileData.Length, "", dto.FileData.OpenReadStream(), dto.Source ?? string.Empty);
|
|
|
return Ok(new { Id = file.Id, fileName = file.FileName });
|
|
|
}
|
|
|
|
|
|
[HttpGet("getfileurl/{id}")]
|
|
|
- public async Task<IActionResult> GetFileUrl(string id)
|
|
|
+ public async Task<IActionResult> GetFileUrl([FromQuery] UploadGetDto dto)
|
|
|
{
|
|
|
- var uri = await _fileStorage.GetFileUrlAsync(id,_sessionContext.ClientId ?? string.Empty);
|
|
|
+ var uri = await _fileStorage.GetFileUrlAsync(dto.Id, dto.Source ?? string.Empty);
|
|
|
return Ok(new { Uri = uri });
|
|
|
}
|
|
|
|
|
|
|
|
|
[HttpGet("downloadfile/{id}")]
|
|
|
- public async Task<IActionResult> DownLoadFile(string id)
|
|
|
+ public async Task<IActionResult> DownLoadFile([FromQuery] UploadGetDto dto)
|
|
|
{
|
|
|
- var (stream, content, fileName) = _fileStorage.DownLoadFile(id,_sessionContext.ClientId ?? string.Empty);
|
|
|
+ var (stream, content, fileName) = _fileStorage.DownLoadFile(dto.Id, dto.Source ?? string.Empty);
|
|
|
if (stream != null)
|
|
|
{
|
|
|
return File(stream, content, fileName);
|
|
@@ -60,9 +57,9 @@ namespace FileStorage.Host.Controllers
|
|
|
}
|
|
|
|
|
|
[HttpGet("delfile/{id}")]
|
|
|
- public async Task<bool> DelFile(string id)
|
|
|
+ public async Task<bool> DelFile([FromQuery] UploadGetDto dto)
|
|
|
{
|
|
|
- return await _fileStorage.DelFileAsync(id,_sessionContext.ClientId?? string.Empty);
|
|
|
+ return await _fileStorage.DelFileAsync(dto.Id, dto.Source ?? string.Empty);
|
|
|
}
|
|
|
|
|
|
|