Upload multiple files at once (resource)

This commit is contained in:
Thomas Fransolet 2021-12-23 14:06:58 +01:00
parent bdbc97c4e1
commit 4b10635522
3 changed files with 26 additions and 22 deletions

View File

@ -51,7 +51,7 @@ namespace ManagerService.Service.Controllers
{
#if DEBUG
email = "test@email.be";
password = "kljqsdkljqsd";
password = "W/7aj4NB60i3YFKJq50pbw=="; // password = "kljqsdkljqsd";
#endif
var token = _tokensService.Authenticate(email.ToLower(), password);

View File

@ -131,7 +131,6 @@ namespace ManagerService.Controllers
/// <summary>
/// Upload a specific resource (picture or video)
/// </summary>
/// <param name="id">id resource</param>
[ProducesResponseType(typeof(string), 200)]
[ProducesResponseType(typeof(string), 404)]
[ProducesResponseType(typeof(string), 500)]
@ -146,8 +145,10 @@ namespace ManagerService.Controllers
uploadResource.type = (ResourceType) Enum.Parse(typeof(ResourceType), type);
uploadResource.label = label;
var file = Request.Form.Files[0];
List<Resource> resources = new List<Resource>();
foreach (var file in Request.Form.Files)
{
if (file.Length > 0)
{
var stringResult = "";
@ -167,12 +168,10 @@ namespace ManagerService.Controllers
resource.DateCreation = DateTime.Now;
resource.Data = stringResult;
Resource resourceCreated = _resourceService.Create(resource);
return Ok(resourceCreated.ToDTO());
resources.Add(resourceCreated);
}
else
{
return BadRequest();
}
return Ok(resources.Select(r => r.ToDTO()));
}
catch (ArgumentNullException ex)
{

View File

@ -145,6 +145,10 @@ namespace ManagerService
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
/*app.UseCors(
options => options.WithOrigins("http://localhost:60109").AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader().AllowCredentials()
);*/
if (env.IsDevelopment())
{
//app.UseDeveloperExceptionPage();
@ -156,6 +160,7 @@ namespace ManagerService
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseCors("AllowAll");
app.UseEndpoints(endpoints =>
{