简体   繁体   English

Asp Net Core C#中的哪种数据类型可用于捕获Angular的blob对象?

[英]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.

相关问题 ASP.Net Core 6 HttpGet API ==&gt; 如何将 [FromQuery] 参数绑定到 C# object 数据类型 - ASP.Net Core 6 HttpGet API ==> How to bind [FromQuery] parameter to C# object data type 将来自asp.net核心的blob数据读取到Angular 7 - Read blob data that comes from asp.net core to Angular 7 在 asp.net 核心 C# 中,哪个命名空间用于将 Byte[] 数组转换为图像? - Which Namespace used to Convert Byte[] array to Image in asp.net core C#? 如何使用 Object c# .NET Core 在 blob 存储 azure 上创建 csv 文件? - How can I create a csv file on blob storage azure with Object c# .NET Core? 从Angular将Json对象解析为C#ASP.Net Core Web API - Parse Json object from Angular to C# ASP.Net Core Web API C#(ASP.NET Core MVC)中的记录类型有什么用? - What's the use of the record type in C# (in ASP.NET Core MVC)? 对于WebApi中的XMLHttpRequest,请使用Blob数据类型向服务器发起请求。 C#.net核心如何接收和解析它? - For the XMLHttpRequest in WebApi, use the blob data type to initiate a request to the server. How does C# .net core receive and parse it? 如何在 asp.net 核心 mvc ZD7EFA19FBE7D39372FD5ADB60242 中将列表 object 转换为 Viewmodel object? - How can I convert List object to Viewmodel object in asp.net core mvc C#? 如何在 asp.net 核心 1.0 c# 中将字符串(实际上是位图)转换为 IFormFile - How can I convert String (which is actually Bitmap) to IFormFile in asp.net core 1.0 c# C#ASP.NET Core-将错误的数据类型传递给部分视图? - C# ASP.NET Core - wrong data type being passed to Partial View?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM