Ejemplo n.º 1
0
        public HttpResponseMessage DownloadPublicDocument(FileResult file)
        {
            HttpResponseMessage result = null;

            //string filename = "36430309-imagenes-hd.jpg";
            string filename = Cryptography.Decrypt(file.LocalFilePath);

            filename = Path.GetFileName(filename);
            string path = DocumentHandling.GetInstance().HandlingDownloadPublicDirectories(filename);

            DocumentValidation.GetInstance().ValidateFileExist(path);
            //if (!File.Exists(path))
            //{
            //    throw new ApiException(7779, "El documento no existe",
            //        System.Net.HttpStatusCode.Gone, "NoLink");
            //}
            //else
            //{
            // Serve the file to the client
            result         = Request.CreateResponse(HttpStatusCode.OK);
            result.Content = new StreamContent(new FileStream(path, FileMode.Open, FileAccess.Read));
            result.Content.Headers.ContentDisposition          = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment");
            result.Content.Headers.ContentDisposition.FileName = filename;
            //}

            return(result);
        }
Ejemplo n.º 2
0
        public HttpResponseMessage DownloadPrivateDocument(FileResult file)
        {
            HttpResponseMessage result = null;

            string username = User.Identity.Name;
            string filename = Cryptography.Decrypt(file.LocalFilePath);

            filename = Path.GetFileName(filename);
            string path = DocumentHandling.GetInstance().HandlingDownloadPrivateDirectories(username, filename);

            DocumentValidation.GetInstance().ValidateFileExist(path);
            // Serve the file to the client
            result         = Request.CreateResponse(HttpStatusCode.OK);
            result.Content = new StreamContent(new FileStream(path, FileMode.Open, FileAccess.Read));
            result.Content.Headers.ContentDisposition          = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment");
            result.Content.Headers.ContentDisposition.FileName = filename;
            //}

            return(result);
        }
Ejemplo n.º 3
0
        public async Task <string> UploadPrivateDocument()
        {
            HttpFileCollection filecol = HttpContext.Current.Request.Files;

            DocumentValidation.GetInstance().CompleteValidations(filecol);
            string username   = User.Identity.Name;
            string uploadPath = DocumentHandling.GetInstance().HandlingUpdatePrivateDirectories(username);
            var    multipartFormDataStreamProvider = new UploadMultipartFormProvider(uploadPath);
            await Request.Content.ReadAsMultipartAsync(multipartFormDataStreamProvider);

            string _localFileName = multipartFormDataStreamProvider
                                    .FileData.Select(multiPartData => multiPartData.LocalFileName).FirstOrDefault();

            return(JsonConvert.SerializeObject(new FileResult
            {
                FileName = Path.GetFileName(_localFileName),
                FileLength = new FileInfo(_localFileName).Length,
                LocalFilePath = Cryptography.Encrypt(_localFileName),
            }));
        }
Ejemplo n.º 4
0
 public override FileValidation ChargeMyValidator()
 {
     return(DocumentValidation.GetInstance());
 }