public void PruebaConsultaFicherosBinarios() { int n = 0; var f = new Ficheros() { datos = "", datosb = new byte[] { }, nombre = "borrar", tipoFichero = 1, tipo = "azure" }; db.Ficheros.Add(f); try { n = db.SaveChanges(); } catch (Exception e) { Console.WriteLine(e); } Assert.IsFalse(n == 0); }
public ActionResult Subida(Ficheros model, HttpPostedFileBase fichero) { if (model.tipo == "interno") { var n = GestionarFicheros.GuardarFicheroDisco(fichero, Server); if (n != null) { model.datos = n; db.Ficheros.Add(model); try { db.SaveChanges(); } catch (Exception e) { Console.WriteLine(e); } } } else if (model.tipo == "base64") { var data = GestionarFicheros.ToBinario(fichero); if (data != null) { model.datos = Convert.ToBase64String(data); model.nombre = fichero.FileName; db.Ficheros.Add(model); try { db.SaveChanges(); } catch (Exception e) { Console.WriteLine(e); } } } else if (model.tipo == "binario") { var datab = GestionarFicheros.ToBinario(fichero); if (datab != null) { model.nombre = fichero.FileName; model.datosb = datab; model.datos = ""; db.Ficheros.Add(model); try { db.SaveChanges(); } catch (Exception e) { Console.WriteLine(e); } } } else if (model.tipo == "azure") { var cu = ConfigurationManager.AppSettings["AccountnameAzureStorage"]; var cl = ConfigurationManager.AppSettings["PasswordAzureStorage"]; var co = ConfigurationManager.AppSettings["ContainerAzureStorage"]; var az = new AzureStorageUtil(cu, cl, co); var n = Guid.NewGuid(); var ext = fichero.FileName.Substring(fichero.FileName.LastIndexOf(".")); az.SubirFichero(fichero.InputStream, n + ext); model.datos = n + ext; model.nombre = fichero.FileName; db.Ficheros.Add(model); db.SaveChanges(); } return RedirectToAction("Index"); }