We are uploading images from .net core web api to Amazon Web Services(AWS) using S3 bucket. And the image we are receiving in request body in Base64 string format in web api controller.
This all works well, however we are having performance issues while uploading the image. As it is take a lot of time to upload.
What we are doing once we receive the Base64 string we convert it to byte array and pass the byte array to aws. We are receiving at least 10 images in request body.
Basically these images are send through mobile app created with ionic/angular js.
We have tried with directly sending the byte array from UI to web api but still it takes the same time. Along with image upload we are also sending the form data.
As these images have size of 6/7 mb per image.
Below is the code for the same.
public class SafetyController : ControllerBase
{
[HttpPost]
public IActionResult Save([FromBody] SafetyModel safetyModel)
{
try
{
SafetyBL safetybl = new SafetyBL();
safetybl.Save();
}
catch (Exception ex)
{
throw ex;
}
}
}
public class SafetyModel
{
public int Id { get; set; }
public string SafetyName { get; set; }
public string SafetyDescription { get; set; }
public string Location { get; set; }
public List<Photo> Photos { get; set; }
}
public class Photo
{
public string Base64{ get; set; }
}
public class Convert()
{
Public byte[] ConvertToByteArray(string base64)
{
return Convert.FromBase64String(base64);
}
}