79565271

Date: 2025-04-09 20:27:27
Score: 1
Natty:
Report link

Here is the solution https://our.umbraco.com/forum/extending-umbraco-and-using-the-api/81065-file-upload-in-backoffice-custom-section

 let fileInput = document.getElementById(`ImageFile`);
  let file = fileInput.files[0];

$http({
    method: 'POST',
    url: "/umbraco/backoffice/api/myController/Create",
    headers: { 'Content-Type': undefined }, // Let the browser set multipart/form-data boundaries
    transformRequest: function () {
      var formData = new FormData();
      if (file) {
        formData.append("file", file);
      }
      formData.append("competition", JSON.stringify(vm.competition)); // Send competition object as string
      return formData;
    }
  })

this is an .net API action method

[HttpPost]
public async Task<IActionResult> Create([FromForm] IFormFile file, [FromForm] string competition)
{
 var competitionData = JsonConvert.DeserializeObject<CompetitionRequest>(competition);
// do service call
}
Reasons:
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: Sargis