0

Getting Null exception

try
{
var contentBytes = APIWebservice.GetPreview(Global.AuthTicket?.Ticket, fileToken, out var fileName,
out var isAuthenticated);

if (!isAuthenticated)
return Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "Not authorized");

var response = new HttpResponseMessage(HttpStatusCode.OK) {Content = new ByteArrayContent(contentBytes)};
response.Content.Headers.ContentType = MediaTypeHeaderValue.Parse(MimeMapping.GetMimeMapping(fileName));
response.Content.Headers.ContentDisposition.FileName = fileName;
response.Content.Headers.ContentDisposition.Size = contentBytes.Length;

return response;
}

Getting issue at response.Content.Headers.ContentType = MediaTypeHeaderValue.Parse(MimeMapping.GetMimeMapping(fileName));

"System.Net.Http.Headers.HttpContentHeaders.ContentDisposition.get returned null."

But the out var fileName having value.

Please..

Ricky
  • 1
  • 2
  • What is the filename? The filename was added in the server code and you may not have access to the folder where the file is stored. – jdweng Dec 24 '21 at 14:40
  • Even I hardcode the filename, still getting the same issue. response.Content.Headers.ContentDisposition.FileName = "TestName.png"; – Ricky Dec 24 '21 at 14:48
  • Is the file on the machine? Do you have read access? – jdweng Dec 24 '21 at 15:09
  • Yes we have a read access, if I comment that particular line, I can see the file. – Ricky Dec 24 '21 at 15:26
  • See following : https://stackoverflow.com/questions/11125535/how-to-return-a-file-using-web-api – jdweng Dec 26 '21 at 12:32

0 Answers0