Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET Core API sending string wrapped in double quotes

My ASP.NET Core API generates a SAS for a file to be uploaded to Azure Blob Storage. Looks like the string is being wrapped in double quotes and this is creating a problem with the front end solution I'm using to upload files.

How can I return a string but make sure that it's not wrapped in double quotes?

This is the API controller:

public async Task<IActionResult> GetSAS(string blobUri, string _method)
{
    if (string.IsNullOrEmpty(blobUri) || string.IsNullOrEmpty(_method))
       return new StatusCodeResult(400);

    // Get SAS
    var sas = _fileServices.GetSAS(blobUri, _method);

    return Ok(sas);
}
like image 382
Sam Avatar asked Dec 28 '17 15:12

Sam


1 Answers

As discussed in the comments you have a [Produces] attribute on the class that is forcing a JSON response. From the docs on ProducesAttribute we can see it can be applied to an action as well as the controller. So, you can override for a particular action by adding it there, in your case you need text/plain:

[Produces("text/plain")]
public async Task<IActionResult> GetSAS(string blobUri, string _method)
{
    //snip
}
like image 65
DavidG Avatar answered Oct 12 '22 22:10

DavidG