0

I am trying to make a Get request to an Azure Function (v1) that uses NReco HtmlToImageConverter, but for some reason I get the 500 status code with the following message

No MediaTypeFormatter is available to read an object of type 'Object' from content with media type 'application/octet-stream'.

EDIT: I don't think the problem is what's described here

I Publish literally empty function V1 to Azure and it doesn't work.

 [FunctionName("Function1")]
    public static async Task<HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)]HttpRequestMessage req, TraceWriter log)
    {
        log.Info("C# HTTP trigger function processed a request.");

        // parse query parameter
        string name = req.GetQueryNameValuePairs()
            .FirstOrDefault(q => string.Compare(q.Key, "name", true) == 0)
            .Value;

        // Get request body
        dynamic data = await req.Content.ReadAsAsync<object>();

        // Set name to query string or body data
        name = name ?? data?.name;

        return name == null
            ? req.CreateResponse(HttpStatusCode.BadRequest, "Please pass a name on the query string or in the request body")
            : req.CreateResponse(HttpStatusCode.OK, "Hello " + name);
    }

I don't know if its related but when I publish I get the following dialog (to which I currently answer with No)

enter image description here

nmrlqa4
  • 659
  • 1
  • 9
  • 32
  • Possible duplicate of [No MediaTypeFormatter is available to read an object of type 'String' from content with media type 'text/plain'](https://stackoverflow.com/questions/12512483/no-mediatypeformatter-is-available-to-read-an-object-of-type-string-from-conte) – KYL3R Apr 25 '18 at 11:04
  • Apparently the popup you see is still an [open issue](https://github.com/Azure/Azure-Functions/issues/667). A solution is also mentioned there.About the exception you get, I can't really help. – Melissa Apr 25 '18 at 12:43

1 Answers1

0

In the HTTP request you need to set Content-Type to:

contentType: 'application/json; charset=utf-8'.

The version of Functions on your Azure host does not match the local version.

It seems that your function runtime in local is v1, but the function on Portal may be "beta", so their versions are not match.

So, you could create a new Azure Function on portal and its default runtime version is "~1".Check the runtime on your Portal in Function app settings as below: enter image description here

Then publish your local function to Azure and it will work fine.

Manglu
  • 10,744
  • 12
  • 44
  • 57
Joey Cai
  • 18,968
  • 1
  • 20
  • 30