Last post Nov 26, 2015 03:08 AM by Krunal Parekh
Nov 24, 2015 06:50 PM|rogersbr|LINK
Using MVC 4, with a remote SQL server, am adding the feature of file upload/download. There is a new table, and there is a foreign key that references the main table's entry so multiple documents can be stored against that entry.
The system Im using does NOT allow for filestream. that is not an option here. There is no directory, everything is in the sql.
Was shown or found this example online: http://rusanu.com/2010/12/28/download-and-upload-images-from-sql-server-with-asp-net-mvc/
but there are 2 problems so far: its from 2010 and Entity Framework or MVC may do things in some newer way? and second, there is no example of actually using this. there is no model for the Media part, and no View. I added everything there into a new
project to test with but am not finding how its invoked?
It seems to be dealing with files in a filesystem on the local machine. after installing all of the code into the project, and making the table from the TSQL, if I do http://localhost:50001/site/Media/IMG0042.JPG
at first it says file not found. so i add a picture and rename it. refresh and its there. just dont know what Im missing here. is this supposed to upload varbinary or store files locally?
a quote from the well written article follows. am just wanting a stable mechanism to upload/download blobs, thanks for any help
Lets say we want to have a virtual Media folder in an ASP.Net MVC site, serving the files from a SQL Server database. A GET request for an URL like "http://site/Media/IMG0042.JPG"should return the content of the file named IMG0042.JPG from the database.
A POST request to the URL "http://site/Media"which contains an embedded file should insert this new file in the database and redirect the response to the newly added file virtual path. This is how our upload HTML form looks like:
<form method="post" action="/Media" enctype="multipart/form-data">
<input type="file" name="file" id="file"/>
<input type="submit" name="Submit" value="Submit"/>
Nov 26, 2015 03:08 AM|Krunal Parekh|LINK
You can use FileContentResult or FilePathResult or FileStreamResult in MVC to provide the file on the client side.