I'm having a bit of an issue uploading files to a database. I'll post snippets of my code below.
The table i'm uploading to has the following structure:
[IDEnsayo] int NOT NULL,
[Nombre] varchar(256) NULL,
[Tipo] varchar(256) NULL,
[Longitud] int NULL,
[Contenido] image NULL
This is the class
public class Archivo
{
public string Nombre { get; set; }
public string Tipo { get; set; }
public long Longitud { get; set; }
public byte[] Contenido { get; set; }
}
I can upload the file using my application without any errors, however in the database the file stores in "Contenido" as "0x0000000000000000......". All the other information relating to the file uploads correctly.
This is my controller code:
public ActionResult Add(Ensayo Ensayo, HttpPostedFileBase uploadFile)
{
var ensayo = new Ensayo { IDEnsayo = Ensayo.IDEnsayo};
ensayo.Archivo.Longitud = uploadFile.ContentLength;
ensayo.Archivo.Nombre = uploadFile.FileName;
ensayo.Archivo.Tipo = uploadFile.ContentType;
byte[] tempFile = new byte[uploadFile.ContentLength];
uploadFile.InputStream.Read(tempFile, 0, uploadFile.ContentLength);
ensayo.Archivo.Contenido = tempFile;
ensayo.SaveArchivo();
//
Other considerations:
- I use: MVC3 + SQL Server 2000.
- When I use the application in a testing environment (local computer + Database server) there is not problem. Files are stored correctly.
- When I use the application in prduction environment (web server + Database server) files are not saved correctly.
- IIS6 on production server
UPDATE
With IE9 works, but with Chrome does not.
This is my submit form code:
@using (Html.BeginForm("Add", "Archivos",FormMethod.Post, new { id = "attachment", enctype = "multipart/form-data" }))
{
@Html.HiddenFor(x => Model.IDEnsayo)
<input type="file" name="uploadFile" id="uploadFile" />
<input type="submit" value="Guardar" class="t-button"/>
}
If anyone could offer help/advice I'd appreciate it alot.
Thanks.