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
|
||||
email = "test@email.be";
|
||||
password = "kljqsdkljqsd";
|
||||
password = "W/7aj4NB60i3YFKJq50pbw=="; // password = "kljqsdkljqsd";
|
||||
#endif
|
||||
var token = _tokensService.Authenticate(email.ToLower(), password);
|
||||
|
||||
|
||||
@ -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,33 +145,33 @@ 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>();
|
||||
|
||||
if (file.Length > 0)
|
||||
foreach (var file in Request.Form.Files)
|
||||
{
|
||||
var stringResult = "";
|
||||
if (file.Length > 0)
|
||||
{
|
||||
using (var ms = new MemoryStream())
|
||||
var stringResult = "";
|
||||
if (file.Length > 0)
|
||||
{
|
||||
file.CopyTo(ms);
|
||||
var fileBytes = ms.ToArray();
|
||||
stringResult = Convert.ToBase64String(fileBytes);
|
||||
using (var ms = new MemoryStream())
|
||||
{
|
||||
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)
|
||||
{
|
||||
|
||||
@ -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 =>
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user