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); }
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); }
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), })); }