Portfolio.Web
1.0.0.0
.NET, Blazor, WPF와 서비스 운영 경험을 프로젝트·이력·기술 스택 단위로 보여주는 개발자 포트폴리오입니다.
Toggle main menu visibility
로딩중...
검색중...
일치하는것 없음
LocalMediaService.cs
이 파일의 문서화 페이지로 가기
1
using
System.IO;
2
using
Microsoft.AspNetCore.Components.Forms;
3
4
namespace
PortfolioApp.Services
;
5
14
public
class
LocalMediaService
:
IMediaService
15
{
24
private
readonly
string
_root
;
33
private
const
long
MaxImageBytes
= 20 * 1024 * 1024;
42
private
const
long
MaxVideoBytes
= 500 * 1024 * 1024;
43
60
public
LocalMediaService
(
PortfolioOptions
opts) =>
_root
= opts.
ResolvedDataPath
;
61
102
public
async Task<string>
SaveAsync
(
string
slug,
string
projectId, IBrowserFile file)
103
{
104
var dir = Path.Combine(
_root
, slug,
"media"
, projectId);
105
Directory.CreateDirectory(dir);
106
var ext = Path.GetExtension(file.Name).ToLowerInvariant();
107
var safe = $
"{Guid.NewGuid():N}{ext}"
;
108
var path = Path.Combine(dir, safe);
109
await
using
var fs =
new
FileStream(path, FileMode.Create);
110
await file.OpenReadStream(
MaxImageBytes
).CopyToAsync(fs);
111
return
safe;
112
}
113
154
public
async Task<string>
SaveVideoAsync
(
string
slug,
string
projectId, IBrowserFile file)
155
{
156
var dir = Path.Combine(
_root
, slug,
"media"
, projectId);
157
Directory.CreateDirectory(dir);
158
var ext = Path.GetExtension(file.Name).ToLowerInvariant();
159
var safe = $
"vid_{Guid.NewGuid():N}{ext}"
;
160
var path = Path.Combine(dir, safe);
161
await
using
var fs =
new
FileStream(path, FileMode.Create);
162
await file.OpenReadStream(
MaxVideoBytes
).CopyToAsync(fs);
163
return
safe;
164
}
165
206
public
Task
DeleteAsync
(
string
slug,
string
projectId,
string
fileName)
207
{
208
var path = Path.Combine(
_root
, slug,
"media"
, projectId, fileName);
209
if
(File.Exists(path)) File.Delete(path);
210
return
Task.CompletedTask;
211
}
212
245
public
async Task<string>
SaveProfileImageAsync
(
string
slug, IBrowserFile file)
246
{
247
var dir = Path.Combine(
_root
, slug,
"media"
,
"_profile"
);
248
Directory.CreateDirectory(dir);
249
var ext = Path.GetExtension(file.Name).ToLowerInvariant();
250
var safe = $
"profile{ext}"
;
251
var path = Path.Combine(dir, safe);
252
await
using
var fs =
new
FileStream(path, FileMode.Create);
253
await file.OpenReadStream(
MaxImageBytes
).CopyToAsync(fs);
254
return
safe;
255
}
256
297
public
string
GetMediaUrl
(
string
slug,
string
projectId,
string
fileName) =>
298
$
"/portfolio-data/{slug}/media/{projectId}/{Uri.EscapeDataString(fileName)}"
;
299
332
public
string
GetProfileImageUrl
(
string
slug,
string
fileName) =>
333
$
"/portfolio-data/{slug}/media/_profile/{Uri.EscapeDataString(fileName)}"
;
334
}
PortfolioApp.Services
Definition
GhostAccountCleanupService.cs:4
PortfolioApp.Services.IMediaService
Definition
IMediaService.cs:14
PortfolioApp.Services.LocalMediaService.MaxVideoBytes
const long MaxVideoBytes
Definition
LocalMediaService.cs:42
PortfolioApp.Services.LocalMediaService.SaveVideoAsync
async Task< string > SaveVideoAsync(string slug, string projectId, IBrowserFile file)
Definition
LocalMediaService.cs:154
PortfolioApp.Services.LocalMediaService.SaveProfileImageAsync
async Task< string > SaveProfileImageAsync(string slug, IBrowserFile file)
Definition
LocalMediaService.cs:245
PortfolioApp.Services.LocalMediaService.DeleteAsync
Task DeleteAsync(string slug, string projectId, string fileName)
Definition
LocalMediaService.cs:206
PortfolioApp.Services.LocalMediaService.GetMediaUrl
string GetMediaUrl(string slug, string projectId, string fileName)
Definition
LocalMediaService.cs:297
PortfolioApp.Services.LocalMediaService._root
readonly string _root
Definition
LocalMediaService.cs:24
PortfolioApp.Services.LocalMediaService.GetProfileImageUrl
string GetProfileImageUrl(string slug, string fileName)
Definition
LocalMediaService.cs:332
PortfolioApp.Services.LocalMediaService.LocalMediaService
LocalMediaService(PortfolioOptions opts)
Definition
LocalMediaService.cs:60
PortfolioApp.Services.LocalMediaService.SaveAsync
async Task< string > SaveAsync(string slug, string projectId, IBrowserFile file)
Definition
LocalMediaService.cs:102
PortfolioApp.Services.LocalMediaService.MaxImageBytes
const long MaxImageBytes
Definition
LocalMediaService.cs:33
PortfolioApp.Services.PortfolioOptions
Definition
PortfolioOptions.cs:15
PortfolioApp.Services.PortfolioOptions.ResolvedDataPath
string ResolvedDataPath
Definition
PortfolioOptions.cs:43
Services
LocalMediaService.cs
다음에 의해 생성됨 :
1.17.0