c# - 如何以角度(打字稿)将图像存储为字节数组
问题描述
我有两个应用程序,一个是 windows 应用程序,另一个是 web 应用程序。Windows 应用程序基于 C#,Web 应用程序基于 C# 和 Angular。他们都使用相同的数据库,我的问题是处理文件。不幸的是,文件内容已通过 Windows 应用程序存储在数据库中,所以我也必须在 Web 应用程序中处理这个问题。这是我在 win 应用程序中的代码:
string FileName = System.IO.Path.GetFullPath(_fnames[i]);// GetFileName(_fname);
string FileDescription = System.IO.Path.GetFullPath(_fnames[i]);
string FileExtension = System.IO.Path.GetExtension(FileName);
System.IO.FileStream _fs = System.IO.File.Open(FileName, System.IO.FileMode.Open);
byte[] _f = new byte[_fs.Length];
_fs.Read(_f, 0, int.Parse(_fs.Length.ToString()));
byte[] FileContent = _f;
if (FileContent != null && FileContent.GetLength(0) > 0)
{
ReceiptDocDS.tblFilesRow _r = MainDS.tblFiles.NewtblFilesRow();
_r.FileContent = FileContent;
_r.FileDescription = FileDescription;
// and other probs
}
我想知道如何以角度处理这个问题。我想将文件的内容存储在fileContet
prop. 所以我必须阅读文件的内容,我进行了研究,结果如下:
onUpload(event) {
const reader = new FileReader();
for(let file of event.files) {
reader.onload = (e) => e.target.result;
const test =reader.readAsDataURL(new Blob([file.objectURL.changingThisBreaksApplicationSecurity]));
this.uploadedFiles.push(file);
}
}
这就是this.file
:
lastModified: 1543877513859
lastModifiedDate: Tue Dec 04 2018 02:21:53 GMT+0330 (Iran Standard Time) {}
name: "ali.jpg"
objectURL: SafeUrlImpl
changingThisBreaksApplicationSecurity: "blob:http://localhost:4200/0ae15950-5bfd-448c-b002-04ed2f27e622"
__proto__: SafeValueImpl
size: 16196
type: "image/jpeg"
webkitRelativePath: ""
我希望在这一行中将图像的内容作为字节数组获取:
const test =reader.readAsDataURL(new Blob([file.objectURL.changingThisBreaksApplicationSecurity]));
但在测试中有注意事项。那么这怎么可能呢?非常感谢阅读的人。
解决方案
推荐阅读
- reactjs - 哨兵/浏览器是否有包含参数以仅包含特定文件?
- sonarqube - 了解 SonarQube 及其测试覆盖率
- javascript - 使用 javascript 从 url 获取后更改 html 内容
- python - 如何将列的类型从字符串转换为日期
- sed - 如何使用 sed 在两个模式之间进行匹配并在第二个模式之后获取下一行?
- javascript - 如何使用NodeJS在Javascript文件中使用函数
- javascript - React-leaflet:地图和标记未居中
- java - 如何覆盖专用于处理异常的 ControllerAdvice
- string - mongodb 使用 Mongo 4.2 将字符串属性转换为 int/double
- visual-studio-code - 在 HTML 标签或其他任意代码中包装代码块