Upload multiple files at once (resource)
This commit is contained in:
parent
bdbc97c4e1
commit
4b10635522
@ -51,7 +51,7 @@ namespace ManagerService.Service.Controllers
|
|||||||
{
|
{
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
email = "test@email.be";
|
email = "test@email.be";
|
||||||
password = "kljqsdkljqsd";
|
password = "W/7aj4NB60i3YFKJq50pbw=="; // password = "kljqsdkljqsd";
|
||||||
#endif
|
#endif
|
||||||
var token = _tokensService.Authenticate(email.ToLower(), password);
|
var token = _tokensService.Authenticate(email.ToLower(), password);
|
||||||
|
|
||||||
|
|||||||
@ -131,7 +131,6 @@ namespace ManagerService.Controllers
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Upload a specific resource (picture or video)
|
/// Upload a specific resource (picture or video)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="id">id resource</param>
|
|
||||||
[ProducesResponseType(typeof(string), 200)]
|
[ProducesResponseType(typeof(string), 200)]
|
||||||
[ProducesResponseType(typeof(string), 404)]
|
[ProducesResponseType(typeof(string), 404)]
|
||||||
[ProducesResponseType(typeof(string), 500)]
|
[ProducesResponseType(typeof(string), 500)]
|
||||||
@ -146,33 +145,33 @@ namespace ManagerService.Controllers
|
|||||||
uploadResource.type = (ResourceType) Enum.Parse(typeof(ResourceType), type);
|
uploadResource.type = (ResourceType) Enum.Parse(typeof(ResourceType), type);
|
||||||
uploadResource.label = label;
|
uploadResource.label = label;
|
||||||
|
|
||||||
var file = Request.Form.Files[0];
|
List<Resource> resources = new List<Resource>();
|
||||||
|
|
||||||
if (file.Length > 0)
|
foreach (var file in Request.Form.Files)
|
||||||
{
|
{
|
||||||
var stringResult = "";
|
|
||||||
if (file.Length > 0)
|
if (file.Length > 0)
|
||||||
{
|
{
|
||||||
using (var ms = new MemoryStream())
|
var stringResult = "";
|
||||||
|
if (file.Length > 0)
|
||||||
{
|
{
|
||||||
file.CopyTo(ms);
|
using (var ms = new MemoryStream())
|
||||||
var fileBytes = ms.ToArray();
|
{
|
||||||
stringResult = Convert.ToBase64String(fileBytes);
|
file.CopyTo(ms);
|
||||||
|
var fileBytes = ms.ToArray();
|
||||||
|
stringResult = Convert.ToBase64String(fileBytes);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
// Todo add some verification ?
|
||||||
|
Resource resource = new Resource();
|
||||||
|
resource.Label = uploadResource.label;
|
||||||
|
resource.Type = uploadResource.type;
|
||||||
|
resource.DateCreation = DateTime.Now;
|
||||||
|
resource.Data = stringResult;
|
||||||
|
Resource resourceCreated = _resourceService.Create(resource);
|
||||||
|
resources.Add(resourceCreated);
|
||||||
}
|
}
|
||||||
// Todo add some verification ?
|
|
||||||
Resource resource = new Resource();
|
|
||||||
resource.Label = uploadResource.label;
|
|
||||||
resource.Type = uploadResource.type;
|
|
||||||
resource.DateCreation = DateTime.Now;
|
|
||||||
resource.Data = stringResult;
|
|
||||||
Resource resourceCreated = _resourceService.Create(resource);
|
|
||||||
return Ok(resourceCreated.ToDTO());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return BadRequest();
|
|
||||||
}
|
}
|
||||||
|
return Ok(resources.Select(r => r.ToDTO()));
|
||||||
}
|
}
|
||||||
catch (ArgumentNullException ex)
|
catch (ArgumentNullException ex)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -145,6 +145,10 @@ namespace ManagerService
|
|||||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||||
{
|
{
|
||||||
|
/*app.UseCors(
|
||||||
|
options => options.WithOrigins("http://localhost:60109").AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader().AllowCredentials()
|
||||||
|
);*/
|
||||||
|
|
||||||
if (env.IsDevelopment())
|
if (env.IsDevelopment())
|
||||||
{
|
{
|
||||||
//app.UseDeveloperExceptionPage();
|
//app.UseDeveloperExceptionPage();
|
||||||
@ -156,6 +160,7 @@ namespace ManagerService
|
|||||||
app.UseRouting();
|
app.UseRouting();
|
||||||
app.UseAuthentication();
|
app.UseAuthentication();
|
||||||
app.UseAuthorization();
|
app.UseAuthorization();
|
||||||
|
app.UseCors("AllowAll");
|
||||||
|
|
||||||
app.UseEndpoints(endpoints =>
|
app.UseEndpoints(endpoints =>
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user