서버에서 이미지를 다운로드하고 브라우저에 표시하고 싶습니다. 하지만 브라우저 (localhost : port/api/service/imageID)에 url을 입력하면 이미지를 저장하거나 열어 보도록 요청하는 다운로드 상자가 나타납니다. 그러나 이미지를 브라우저에 곧바로 표시하고 싶습니다.ASP .net Web Api 이미지 다운로드 및보기
public HttpResponseMessage Get(int id)
{
HttpResponseMessage response;
var image = _repository.RetrieveImage(id);
if (image == null)
{
response = new HttpResponseMessage(HttpStatusCode.NotFound);
}
else
{
response = new HttpResponseMessage(HttpStatusCode.OK);
response.Content = new StreamContent(new MemoryStream(image.ImageData));
response.Content = new ByteArrayContent(image.ImageData);
response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");
response.Content.Headers.ContentDisposition.FileName = image.OriginalFileName;
response.Content.Headers.ContentType = new MediaTypeHeaderValue(image.Mime);
response.Content.Headers.ContentLength = image.ImageData.Length;
}
return response;
덕분에 "첨부 파일"내용 처리 헤더를 사용하지 마십시오 도움
: 당신이 저장시 파일 이름을 유지하려면
Content-Disposition
에 "인라인"로 변경. 그냥'StreamContent'를 사용해 보셨나요? –예,하지만 작동하지 않습니다. 나는 디지털 ID – aimyas