Skip to content
Snippets Groups Projects
Commit 08d131fb authored by Marcel Nellesen's avatar Marcel Nellesen
Browse files

Merge branch 'Sprint/2021-07' into 'master'

Sprint/2021 07

See merge request !31
parents 97799e8f ac9343c7
Branches
Tags
1 merge request!31Sprint/2021 07
......@@ -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");
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment