3

I have the following resource in ASP.NET WebAPI project:

[HttpGet]
[Route("api/v1/things/{id:int}")]
[ResponseType(typeof(Model.Thing))]
public IHttpActionResult Get(int id)
{
    var client = new ThingApiClient(THING_API, Log.Logger, Log.Logger);
    var apiResult = client.Get(id);

    if (apiResult == null)
    {
        return NotFound();
    }

    var result = Mapper.Instance.Map<Api.Model.Thing, Model.Thing>(apiResult);

    return Ok(result);
}

And something similar for the POST and PUT.

It occurs that some parts of the result are just super heavy due to some big base64 image string... which quickly can reach the request length size...

I am wondering what kind of workaround can be implemented to overcome the limitation for the requests (on POST and PUT), I was reading about streaming, websockets, just increasing the size of the request, etc.

The API is consumed by an Angular application for the front-end

Natalie Perret
  • 8,013
  • 12
  • 66
  • 129
  • Do you want to show Image in Angular with Asp.net Web API? – Mohammad Daliri Jul 23 '18 at 19:04
  • Well I am already displaying pictures based on the result and we also update pictures as part of an object representing a configuration. Let's say that thing { name:..., backgroundImage: ...., profilePicture:.., etc.} It's just that the size of the request and response can be huge with certain pictures... – Natalie Perret Jul 23 '18 at 19:09
  • 1
    Possible duplicate of [How to modify the default allowed response size settings for a Web API Application?](https://stackoverflow.com/questions/16436533/how-to-modify-the-default-allowed-response-size-settings-for-a-web-api-applicati) – Zoltán Tamási Jul 23 '18 at 19:14
  • If you want to upload huge file read this [link](https://stackoverflow.com/a/45927665/2585074) – Mohammad Daliri Jul 23 '18 at 19:14
  • @ZoltánTamási, not necessarily I've read somewhere something about streaming and websockets... – Natalie Perret Jul 23 '18 at 19:15
  • @EhouarnPerret according to my best knowledge those are ment for different purposes, although I personally don't have too much experience with them. – Zoltán Tamási Jul 23 '18 at 19:17
  • What occurs? What error message do you get? You need to make sure you're using streams to read and save the file and also the request timeout should be long enough as well. (HttpContext.Current.Server.ScriptTimeout). Base64 is just a serialized binary representation and doesn't differ much than an any other binary file. – Tim Davis Jul 24 '18 at 13:58

0 Answers0