public async Task <IActionResult> Upload() { try { var file = Request.Form.Files[0]; List <int> idUser = new List <int>(); Request.Form.Keys .Where(n => n.StartsWith("idUser")) .ToList() .ForEach(x => idUser.Add(int.Parse(Request.Form[x]))); if (file.Length > 0) { using (var ms = new MemoryStream()) { file.CopyTo(ms); var fileBytes = ms.ToArray(); string s = Convert.ToBase64String(fileBytes); // obter Usuário try { _service.SalvarImagemPerfil(idUser.FirstOrDefault(), s); return(Ok()); } catch (BusinessException e) { if (e.Message.Equals("user not found")) { return(Ok("user not found")); } else if (e.Message.Equals("update failed")) { return(BadRequest()); } } catch (DbConcurrencyException e) { return(this.StatusCode(StatusCodes.Status500InternalServerError, "Banco de dados Falhou, pelo motivo: {0}" + e)); } } } } catch (System.Exception e) { return(this.StatusCode(StatusCodes.Status500InternalServerError, e)); } return(BadRequest("Erro ao tentar realizar Upload")); }