You're implementing an API endpoint that should return a file to the user. However, if the file is not found, you want to return a custom error message in JSON format. How can you best achieve this mixed response type?

  • PhysicalFile
  • File
  • NotFound
  • BadRequest
To achieve the desired behavior of returning a file if found or a custom error message in JSON format if not found, you can use the File action result. This result allows you to return a file if it exists or handle the "file not found" scenario by constructing a custom JSON response. It provides the flexibility needed for this mixed response type.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *