ASP.NET Core API sending double quoted string

My ASP.NET Core API generates SASfor a file to be uploaded to Azure Blob storage. It looks like the string is wrapped in double quotes, and this creates a problem with the front-end solution that I use to upload files.

How can I return a string but not wrap it 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);
}
+4
source share
2 answers

, [Produces] , JSON. docs ProducesAttribute , , . , , , text/plain:

[Produces("text/plain")]
public async Task<IActionResult> GetSAS(string blobUri, string _method)
{
    //snip
}
+5

OkResult, . , JSON, JSON, .. .

, . -, string. ContentResult , . :

public async Task<string> GetSAS(string blobUri, string _method)
{
    ...

    return sas;
}

-, Produces, text/plain.

[Produces("text/plain")]
public async Task<IActionResult> GetSAS(string blobUri, string _method)

, , JSON . JSON.parse JavaScript-, :

var sas = JSON.parse(result);
+2

Source: https://habr.com/ru/post/1691468/


All Articles