Skip to content
Snippets Groups Projects

Sprint/2021 07

Merged Marcel Nellesen requested to merge Sprint/2021-07 into master
1 file
+ 15
6
Compare changes
  • Side-by-side
  • Inline
@@ -9,6 +9,7 @@ using Coscine.ResourceLoader;
using Coscine.ResourceTypeBase;
using Coscine.WaterbutlerHelper.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.StaticFiles;
using Microsoft.Extensions.Logging;
@@ -16,7 +17,6 @@ using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Web;
@@ -185,10 +185,12 @@ namespace Coscine.Api.Blob.Controllers
/// </summary>
/// <param name="resourceId">Id of the resource </param>
/// <param name="path">Path to the file</param>
/// <param name="files">List of files.</param>
/// <returns>Statuscode 204 if file is uploaded otherwise Statuscode 400 or 403</returns>
[HttpPut("[controller]/{resourceId}/{*path}")]
[DisableRequestSizeLimit]
public async Task<IActionResult> UploadFile(string resourceId, string path)
[RequestFormLimits(MultipartBodyLengthLimit = long.MaxValue)]
[HttpPut("[controller]/{resourceId}/{*path}")]
public async Task<IActionResult> UploadFile(string resourceId, string path, List<IFormFile> files)
{
var user = _authenticator.GetUser();
path = $"/{path}";
@@ -207,6 +209,12 @@ namespace Coscine.Api.Blob.Controllers
{
return checkUser;
}
if (files.Count != 1)
{
return BadRequest($"Only one file can be uploaded per request.");
}
var id = GenerateId(resourceId, path);
if (!_rdfStoreConnector.HasGraph(id.AbsoluteUri))
{
@@ -217,7 +225,8 @@ namespace Coscine.Api.Blob.Controllers
try
{
var resourceTypeOptions = _resourceModel.GetResourceTypeOptions(resource.Id);
resourceTypeOptions.Add("ContentLength", Request.ContentLength.ToString());
var stream = files[0].OpenReadStream();
resourceTypeOptions.Add("ContentLength", stream.Length.ToString());
var resourceTypeDefinition = ResourceTypeFactory.CreateResourceTypeObject(resource.Type.DisplayName, _configuration);
if (resourceTypeDefinition == null)
{
@@ -232,11 +241,11 @@ namespace Coscine.Api.Blob.Controllers
{
// do nothing
}
await resourceTypeDefinition.StoreEntry(resource.Id.ToString(), path, Request.Body, resourceTypeOptions);
await resourceTypeDefinition.StoreEntry(resource.Id.ToString(), path, stream, resourceTypeOptions);
LogAnalytics(infos == null ? "Upload File" : "Update File", resourceId, path, user);
return NoContent();
}
catch
catch (Exception e)
{
return BadRequest($"Error in communication with the resource");
}
Loading