public IActionResult DownloadCustomPropFile(int materialId, Guid propId) { try { // Get custom prop and validate type CustomMaterialProp prop = CustomMaterialPropService.GetCustomMaterialProp(propId); if (prop.Type != PropType.File) { return(HandleBadRequest("The submitted prop is not of the type `file`.")); } // Get and validate file path string path = MaterialsService.GetCustomPropFilePath(materialId, prop); if (string.IsNullOrWhiteSpace(path)) { return(NotFound(new ClientErrorResponse("File could not be found!"))); } string fileName = Path.GetFileName(path); byte[] fileBytes = System.IO.File.ReadAllBytes(path); string contentType = "application/octet-stream"; new FileExtensionContentTypeProvider().TryGetContentType(fileName, out contentType); return(File(fileBytes, contentType, fileName)); } catch (CustomPropNotFoundException exception) { return(HandleResourceNotFoundException(exception)); } catch (MaterialNotFoundException exception) { return(HandleResourceNotFoundException(exception)); } catch (Exception exception) { return(HandleUnexpectedException(exception)); } }