Skip to content
Snippets Groups Projects
Commit ac1172f8 authored by Benedikt Heinrichs's avatar Benedikt Heinrichs
Browse files

New: Implement GetUploadUrl (coscine/issues#1451)

parent 40c4916a
No related branches found
Tags test
No related merge requests found
......@@ -180,6 +180,53 @@ namespace Coscine.Api.Blob.Controllers
}
}
/// <summary>
/// This method returns the upload url for a resource and path
/// </summary>
/// <param name="resourceId">Id of the resource</param>
/// <param name="path">Path to the to uploaded file</param>
/// <returns>Uri of the upload url</returns>
[HttpGet("[controller]/uploadUrl/{resourceId}/{*path}")]
public async Task<IActionResult> GetUploadUrl(string resourceId, string path)
{
var rawPath = path;
var user = _authenticator.GetUser();
path = $"/{path}";
var checkPath = CheckPath(path);
if (checkPath != null)
{
return checkPath;
}
var checkResourceId = CheckResource(resourceId, out Resource resource);
if (checkResourceId != null)
{
return checkResourceId;
}
var checkUser = CheckUser(user, resource);
if (checkUser != null)
{
return checkUser;
}
var resourceTypeOptions = _resourceModel.GetResourceTypeOptions(resource.Id);
var resourceTypeDefinition = ResourceTypeFactory.CreateResourceTypeObject(resource.Type.DisplayName, _configuration);
if (resourceTypeDefinition == null)
{
return BadRequest($"No provider for: \"{resource.Type.DisplayName}\".");
}
var entryStoreUrl = await resourceTypeDefinition.GetEntryStoreUrl(rawPath, null, resourceTypeOptions);
if (entryStoreUrl == null)
{
var hostUrl = await _configuration.GetStringAsync("coscine/local/api/additional/url");
var apiPath = $"/coscine/api/{((System.Reflection.Assembly.GetEntryAssembly() != null) ? System.Reflection.Assembly.GetEntryAssembly().GetName().Name : System.Reflection.Assembly.GetExecutingAssembly().GetName().Name)}";
entryStoreUrl = new Uri($"{hostUrl}{apiPath}/Blob/{resourceId}/{rawPath}");
}
return Ok($"{{ \"data\": {{ \"entryStoreUrl\": \"{entryStoreUrl}\" }} }}");
}
/// <summary>
/// This method uploads a given File
/// </summary>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment