[英]Which data type in Asp Net Core C# can be used to catch Angular's blob object?
I have a BLOB object of an image in Angular 5, which I want to send it to backend via api. 我在Angular 5中有一个图像的BLOB对象,我想通过api将其发送到后端。 In backend which data type shall I use to capture the same. 在后端,我应该使用哪种数据类型来捕获相同的数据。 I am aware that in previous versions of Asp.Net there was 'HttpBaseType' but in core it is not available. 我知道在Asp.Net的早期版本中有“ HttpBaseType”,但在核心中不可用。
Therefore which datatype to be used for getting BLOB object of Angular in Asp.Net core c#? 因此,在Asp.Net核心c#中将使用哪种数据类型来获取Angular的BLOB对象?
Update : My use case is that I am drawing an image using canvas and getting its BLOB in Angular. 更新 :我的用例是我正在使用画布绘制图像,并在Angular中获取其BLOB。 Now I want this blob to be received at back-end. 现在,我希望在后端接收此Blob。 But I am not getting suitable type for the same. 但是我没有得到适合的类型。 Here there is no involvement of file at all! 这里根本不涉及文件!
(I am not trying to upload the image/file) (我不尝试上传图像/文件)
Angular's blobs are merely just files (most of the time). Angular的blob只是文件(大多数情况下)。 You should be able to use ASP.NET Core's IFormFile to easily capture incoming data. 您应该能够使用ASP.NET Core的IFormFile轻松捕获传入的数据。
Blobs are merely files, if you are sending that request already, inspect your browser and look at the raw request. Blob只是文件,如果您已经发送了该请求,请检查您的浏览器并查看原始请求。 If you do not want to use files then you'll have to create your own way of parsing the data. 如果您不想使用文件,则必须创建自己的数据解析方法。
I read some posts on it and it seems that Angular sends blobs attached as a file to a form. 我读了一些关于它的文章,看来Angular将附加的blob作为文件发送到了表单。 If you still don't want to do that then you can follow this post to encode it as base64 and do it yourself. 如果您仍然不想这样做,那么可以按照这篇文章将其编码为base64并自己进行。
Here's how I would do it using IFormFile: 使用IFormFile的方法如下:
[HttpPost("upload_blob")]
public async Task<IActionResult> Post(IFormFile file)
{
Console.WriteLine(file.ContentType);
// process uploaded files
// Don't rely on or trust the FileName property without validation.
return Ok("some result");
}
Lastly, here are some posts you can look at: 最后,这是您可以查看的一些帖子:
MDN post about blobs 有关Blob的MDN帖子
IFormFile example by Microsoft Microsoft的IFormFile示例
IFormFile documentation IFormFile文档
I hope I was of help, cheers! 希望我能帮上忙,加油!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.