简体   繁体   中英

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. 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.

Therefore which datatype to be used for getting BLOB object of Angular in Asp.Net core c#?

Update : My use case is that I am drawing an image using canvas and getting its BLOB in Angular. Now I want this blob to be received at back-end. 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). You should be able to use ASP.NET Core's IFormFile to easily capture incoming data.

Blobs are merely files, if you are sending that request already, inspect your browser and look at the raw request. 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. If you still don't want to do that then you can follow this post to encode it as base64 and do it yourself.

Here's how I would do it using 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

IFormFile example by Microsoft

IFormFile documentation

I hope I was of help, cheers!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM