Hello, I am trying to publish an image through an endpoint and for that I need to receive a parameter. The method works fine but as long as you don't send a . in the path eg: api/images/GetImagenLink/xxxxx
But if I put a dot to specify the format eg: api/images/GetImagenLink/xxxxx.jpg then it crashes and gives an error.
How can I receive something like image.png as a parameter in the URL????
[System.Web.Http.Route("api/imagenes/GetImagenLink/{articulo}")]
// GET: api/Imagenes
public async Task<HttpResponseMessage> GetImagenLink(string articulo)
{
HttpResponseMessage result = new HttpResponseMessage();
try
{
noef.controllers.selects consulta = new noef.controllers.selects();
noef.models.Conexion conexion = new noef.models.Conexion
{
Servidor = "xxxxxx",
BD = "xxxxx",
Usuario = "xxx",
Password = "xxx"
};
string[] split = articulo.Split('.');
List<object> objetos = await consulta.SelectFromDatabase(conexion, $"SELECT [ARTICULO],[FOTO],[ARCHIVO] FROM xxxxx where ARTICULO = '{split[0]}'");
var serial = JsonConvert.SerializeObject(objetos, Formatting.Indented);
var desereal = JsonConvert.DeserializeObject<List<Respuesta>>(serial);
var source = desereal.Where(x => x.Columna.ToString() == "FOTO").FirstOrDefault();
var array = source.Valor;
result.Content = new ByteArrayContent(Convert.FromBase64String(array.ToString()));
result.Content.Headers.ContentType = new MediaTypeHeaderValue("image/split[1]");
result.StatusCode = HttpStatusCode.OK;
return result;
}
catch (Exception d)
{
result.StatusCode = HttpStatusCode.BadRequest;
return result;
}
}
Try putting one
/
at the end of the url, like beingI remember that this allowed to close the uri and define the parameter
Use parameter in the URL
Your URL would look like this: api/images/GetImagenLink?article=xxxxx.jpg
I hope it helps you.