47 lines
1.0 KiB
C#
47 lines
1.0 KiB
C#
using BlazorApp1.Handler.Interfaces;
|
|
using Microsoft.AspNetCore.Components.Forms;
|
|
|
|
namespace BlazorApp1.Handler;
|
|
|
|
public class FileHandler : IFileHandler
|
|
{
|
|
private readonly string _tempPath;
|
|
|
|
public FileHandler()
|
|
{
|
|
_tempPath = Directory.GetCurrentDirectory() + "/wwwroot/Videos/Temp/";
|
|
}
|
|
|
|
public async Task SaveFile(IBrowserFile file)
|
|
{
|
|
if (!Directory.Exists(_tempPath))
|
|
{
|
|
Directory.CreateDirectory(_tempPath);
|
|
}
|
|
|
|
await using FileStream fs = new(_tempPath + file.Name, FileMode.Create);
|
|
await file.OpenReadStream(1048576000).CopyToAsync(fs);
|
|
}
|
|
|
|
public async Task<bool> DeleteTempFile(string filePath)
|
|
{
|
|
if (!File.Exists(filePath))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
File.Delete(filePath);
|
|
|
|
return true;
|
|
}
|
|
|
|
public string GetFileReference(string filename)
|
|
{
|
|
if (!File.Exists(_tempPath + filename))
|
|
{
|
|
return "";
|
|
}
|
|
|
|
return _tempPath + filename;
|
|
}
|
|
} |