Example #1
0
        public FileResult ObtenerArchivo(Guid id)
        {
            var archivo = new Repositorio <Archivo>(db).Traer(id);
            var name    = archivo.Nombre;

            byte[] byteArchivo;

            ws.filemanager.Service1SoapClient client = new ws.filemanager.Service1SoapClient();

            if (Guid.TryParse(name, out id))
            {
                byteArchivo = client.GetFile(id);
            }
            else
            {
                byteArchivo = client.GetFileByName(name);
            }


            Response.Headers.Add("Etag", "\"" + name.ToLower().Split('-').First() + ":0\"");
            Response.Cache.SetExpires(DateTime.Now.AddHours(24));
            Response.Cache.SetLastModified(new DateTime(2017, 01, 02));
            Response.Cache.SetCacheability(HttpCacheability.Public);

            return(File(byteArchivo, System.Net.Mime.MediaTypeNames.Application.Octet, "Archivo." + archivo.Contenido));
        }
Example #2
0
        public FileResult GetFileByName(string name)
        {
            ws.filemanager.Service1SoapClient client = new ws.filemanager.Service1SoapClient();

            var file = client.GetFileByName(name);

            return(File(file, System.Net.Mime.MediaTypeNames.Application.Octet, name));
        }
Example #3
0
        public ActionResult ObtenerImagen(string name, string height = null, string width = null, string mode = "crop", int quality = 100)
        {
            ws.filemanager.Service1SoapClient client = new ws.filemanager.Service1SoapClient();

            Guid id = Guid.Empty;

            byte[] imageData;

            if (Guid.TryParse(name, out id))
            {
                imageData = client.GetFile(id);
            }
            else
            {
                imageData = client.GetFileByName(name);
            }

            if (imageData == null)
            {
                return(null);
            }

            int?heightValue = null;
            int?widthValue  = null;

            if (height != null)
            {
                heightValue = Convert.ToInt32(height);
            }
            if (width != null)
            {
                widthValue = Convert.ToInt32(width);
            }

            var modificado = ImageHelper.ResizeImage(imageData, heightValue, widthValue, mode, quality);

            Response.Headers.Add("Etag", "\"" + name.ToLower().Split('-').First() + height + width + mode + quality + ":0\"");
            Response.Cache.SetExpires(DateTime.Now.AddHours(24));
            Response.Cache.SetLastModified(new DateTime(2017, 01, 02));
            Response.Cache.SetCacheability(HttpCacheability.Public);

            return(File(modificado, System.Net.Mime.MediaTypeNames.Application.Octet, name));
        }
Example #4
0
        private string SetFile(out bool isSavedSuccessfully)
        {
            isSavedSuccessfully = true;
            string fName      = "";
            string fExtension = "";
            Guid   id         = Guid.Empty;

            byte[] data = new byte[] { };

            foreach (string fileName in Request.Files)
            {
                HttpPostedFileBase file = Request.Files[fileName];

                MemoryStream target = new MemoryStream();
                file.InputStream.CopyTo(target);
                data = target.ToArray();

                fName = file.FileName;
                if (file.ContentType.Contains("/"))
                {
                    fExtension = file.ContentType.Split('/').Last();
                }
                else
                {
                    fExtension = file.ContentType;
                }

                if (file != null && file.ContentLength > 0)
                {
                    ws.filemanager.Service1SoapClient client = new ws.filemanager.Service1SoapClient();
                    client.InnerChannel.OperationTimeout = new TimeSpan(0, 5, 0);
                    bool error = false;

                    id = client.SetFile(data, fName, out error);
                }
            }


            return(id.ToString() + "." + fExtension);
        }