How do I send file data to an UmbracoAuthorizedApiController in umbraco 8?
I have the following logic that worked previously in umbraco 7.
The API Request
$http({
method: 'POST',
url: '/umbraco/backoffice/feed/feedapi/collectdata',
headers: { 'Content-Type': undefined },
transformRequest: function (data) {
var formData = new FormData();
formData.append("file", data.file);
return formData;
},
data: {
file: ctrl.settings.file
}
});
The API
public async Task<IHttpActionResult> CollectData() {
if (!Request.Content.IsMimeMultipartContent()) {
return BadRequest("Unsupported media type.");
}
var id = Guid.NewGuid();
var uploadFolder = SetupFolders(id);
var provider = new NamedMultipartFormDataStreamProvider(uploadFolder);
var result = await Request.Content.ReadAsMultipartAsync(provider);
var file = result.FileData.First();
var path = $"{uploadFolder}\\{file.Headers.ContentDisposition.FileName.Replace("\"", "")}";
var jsonData = ParseJson(System.IO.File.ReadAllText(path));
return Ok(new JObject {
{"id", id },
{"link", jsonData["link"] },
{ "items", jsonData["items"] }
});
}
All this api is doing is uploading a file selected with a file input to the server for further processing. The problem is that result.FileData has no data, so it fails. Any ideas?
How do I send file data to an UmbracoAuthorizedApiController in umbraco 8?
I have the following logic that worked previously in umbraco 7.
The API Request
The API
All this api is doing is uploading a file selected with a file input to the server for further processing. The problem is that result.FileData has no data, so it fails. Any ideas?
For reference, the submitted data looks like
when I submit to the api.
I was able to resolve this by using the Upload service that Umbraco has already installed. My final code ended up looking like.
The rawFile object is set with ng-model, as shown below.
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.