Hello Stackoverflow community,
I am getting following error message while downloading a file from Web API Controller.
Non-invocable member 'File' cannot be used like a method
This is my database table:
CREATE TABLE [cafe].[t06_03_02_jobAttachments](
[ID] [int] IDENTITY(1,1) NOT NULL,
[jobAttachmentId] [int] NOT NULL,
[jobId] [int] NOT NULL,
[file] [varbinary](max) NOT NULL,
[name] [varchar](100) NOT NULL,
[fileExtension] [varchar](10) NOT NULL,
[contentType] [varchar](50) NOT NULL,
[fileSize] [int] NOT NULL
) ON [PRIMARY]
This is my Data Model:
namespace api.Models.Jobs
{
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.Spatial;
[Table("cafe.t06_03_02_jobAttachments")]
public partial class t06_03_02_jobAttachments
{
public int ID { get; set; }
public int jobAttachmentId { get; set; }
public int jobId { get; set; }
[Required]
public byte[] file { get; set; }
[Required]
[StringLength(100)]
public string name { get; set; }
[Required]
[StringLength(10)]
public string fileExtension { get; set; }
[Required]
[StringLength(50)]
public string contentType { get; set; }
public int fileSize { get; set; }
}
}
Here is my controller code:
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using System.Web.Http;
using System.Web.Http.Description;
using api.Models;
using api.Models.Jobs;
using System.Data.SqlClient;
using System.Text;
using System.IO;
using System.Web.Mvc;
namespace api.Controllers.jobs
{
public class JobsController : ApiController
{
[HttpGet]
[ResponseType(typeof(t06_03_02_jobAttachments))]
public async Task<IHttpActionResult> Gett06_03_02_jobAttachments(int id)
{
t06_03_02_jobAttachments t06_03_02_jobAttachments = await db.t06_03_02_jobAttachments.FindAsync(id);
if (t06_03_02_jobAttachments == null)
{
return NotFound();
}
return File(t06_03_02_jobAttachments.file, t06_03_02_jobAttachments.contentType, t06_03_02_jobAttachments.name);
}
}
}
I am getting this error on my controller when I try to return File as a text file. All I want to do is read the file (saved as Byte array in database) and return it to my Angular application. I have tried multiple solutions posted online but non of them helped me. I would appreciate any help I receive from this blog. I am using .NET Framework 4.6.1 and MVC 5.2.7. Thanks