Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at

  • Ross Ekberg 111 posts 319 karma points
    1 week ago
    Ross Ekberg

    I am attempting to post form data to the server. This form is in the backoffice in a custom section, on a custom dashboard. The form data contains a file to upload. I am not having any luck here. If someone can point me in the right direction, that would be great.


    <div ng-controller="SubscriptionsController">
            <strong>Add New Item</strong>
            <table cellpadding="5">
                    <td><input type="text" name="txtNewSubTitle" ng-model="newSub.title" required no-dirty-check /></td>
                    <td>Post Date:</td>
                    <td><umb-date-time-picker ng-model="newSub.postDate" options='{dateFormat: "m-d-Y"}' id="txtNewSubPostDate"></umb-date-time-picker></td>
                    <td><input type="file" id="fuNewSubFile" /></td>
                    <td><input type="checkbox" id="chkNewSubActive" ng-model="" /></td>
                    <td colspan="2"><input type="checkbox" id="chkNewSubSendNotifications" ng-model="newSub.notify" /> - Check this box to send notification to subscribers</td>
                    <td align="right">
                        <input type="submit" ng-click="SaveSub()" value="Save" />


        angular.module('umbraco').controller('SubscriptionsController', function ($scope, $http, SubscriptionsResource) {
            $scope.newSub = {};        
            $scope.SaveSub = function () {
                var fileInput = document.getElementById('fuNewSubFile');
                var file = fileInput.files[0];    
                $scope.newSub.file = file;
                var payload = new FormData();
                payload.append("newSub", $scope.newSub);
               SubscriptionsResource.SaveNewSub(payload).then(function (response) {
                    alert("server says: " +;


        function ($q, $http) {        
            var saveNewSubResult = function (payload) {
                return $http({
                    url: "backoffice/My/SubscriptionsApi/SaveSub/",
                    method: 'POST',
                    data: payload,
                    headers: { 'Content-Type': undefined },
                    transformRequest: angular.identity
            return {
                SaveNewSub: saveNewSubResult

    Server-side API controller:

    using System;
    using System.IO;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Data;
    using System.Data.SqlClient;
    using Umbraco.Web.WebApi;
    using Umbraco.Web.Editors;
    using Umbraco.Core.Persistence;
    using System.Web.Script.Serialization;
    using Bridge.Models;
    using System.Web.Mvc;
    using Umbraco.Web.Mvc;
    namespace My.Controllers
        public class NewSubFormData
            public string title { get; set; }
            public DateTime postDate { get; set; }
            public HttpPostedFileBase file { get; set; }
            public bool active { get; set; }
            public bool notify { get; set; }
        public class SubscriptionsAPIController : UmbracoAuthorizedApiController
            public string SaveSub(NewSubFormData newSub) 
                return "Success";    

    When I click "submit", I get the following errors:

    "The request entity's media type 'text/plain' is not supported for this resource."

    No MediaTypeFormatter is available to read an object of type 'NewSubFormData' from content with media type 'text/plain'

  • Huw Reddick 1031 posts 3490 karma points c-trib
    1 week ago
Please Sign in or register to post replies

Write your reply to: