Pavlo Sobchuk
Pavlo Sobchuk

Reputation: 1584

Send data from web API controller into separate asp.net mvc website

I have the following situation:

There are two different projects in our solution:

  1. asp.net mvc website
  2. asp.net web api (service for mobile apps).

Users should have an ability to upload profile pictures from their mobile apps using mobile web api project. But the problem is that images are physically stored on different server at asp.net mvc website.

So here is the flow:

  1. User uploads picture and sends it to mobileapidomain/api/user/uploadpicture. (base64)
  2. Now I have to send this image to asp.net mvc site and store it on asp.net mvc server.

What is the best way to send current base64 string with image from web api controller into asp.net mvc project?

Upvotes: 0

Views: 690

Answers (1)

mr100
mr100

Reputation: 4428

In such situation I think the best option would be to install within your mvc web application project packages for WebApi and make this project web application (normal usage) and web service at the same time. Then create new ApiController like this:

[HttpPost]
public IHttpActionResult UploadPicture(string base64)
{
    // Do something with image
    return Ok();
}

If you do not wish to install WebApi libraries there then I would suggest adding new regular Controller for uploading pictures and adding there similar action:

[HttpPost]
public void UploadPicture(string base64)
{
    // Do something with image
}

If something goes wrong within the acton throw exception to inform peer that something wrong is going on. If the file is too long to send in one post I would suggest splitting it and concatenating within mvc application as it receives new portions of it.

Upvotes: 1

Related Questions