-2

I need when client send the id of user , i return file for it as stream. File may be image, PDF, video or sound.

I'm using this code:

[HttpGet]
public async Task<FileStreamResult> GetAvatar(int id)
{
    var result = await mediator.Send(new FindUserWithIdCommand { userId = id });
    if (result.Success)
    {
        return uploadService.GetFileStream(result.Result.AvatarName);
    }
    return null;
}

Upload service:

public FileStreamResult GetFileStream(string FileName)
{
    try
    {
        var stream = File.OpenRead(Path.Combine(finder.PathAvatarUserUploadFolder(), FileName));
        FileStreamResult file = new FileStreamResult(stream, "application/octet-stream");
        return file;
    }
    catch (Exception ex)
    {
        throw;
    }
}

but when i send a request for this action in postMan it show me this result:

The result in post man

Where's the problem and how can I solve it?

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291

1 Answers1

1

Your code is doing exactly what it is supposed to. What you're seeing is byte-code, because Postman doesn't support native rendering of things like PDFs. It is the file; it's just being displayed "raw".

Chris Pratt
  • 232,153
  • 36
  • 385
  • 444