-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebFileInfo.cs
More file actions
54 lines (50 loc) · 1.49 KB
/
Copy pathWebFileInfo.cs
File metadata and controls
54 lines (50 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using ImageCore;
using Microsoft.AspNetCore.Http;
using FileInfo = ImageCore.FileInfo;
namespace ImageApi.Core
{
public class WebFileInfo : FileInfo
{
protected override Task CopyToAsync(Stream stream)
{
return File.CopyToAsync(stream);
}
private IFormFile _file;
public IFormFile File
{
get => _file;
set
{
if (value != null)
{
this._file = value;
this.FileType = this._file.ContentType;
this.Length = this._file.Length;
this.Extension = this._file.FileName.Substring(_file.FileName.LastIndexOf('.'));
if (string.IsNullOrEmpty(this.FileName))
this.FileName = this._file.FileName;
}
}
}
private byte[] _fileBytes;
public byte[] FileBytes
{
get
{
if (_fileBytes != null || _file == null) return _fileBytes;
using (var fileStream = _file.OpenReadStream())
{
_fileBytes = new byte[_file.Length];
fileStream.Read(_fileBytes, 0, _fileBytes.Length);
return _fileBytes;
}
}
set => _fileBytes = value;
}
}
}