public async Task <string> UploadPublicPicture() { HttpFileCollection filecol = HttpContext.Current.Request.Files; PictureValidation.GetInstance().CompleteValidations(filecol); string uploadPath = PictureHandling.GetInstance().HandlingUpdatePublicDirectories(); var multipartFormDataStreamProvider = new UploadMultipartFormProvider(uploadPath); await Request.Content.ReadAsMultipartAsync(multipartFormDataStreamProvider); string _localFileName = multipartFormDataStreamProvider .FileData.Select(multiPartData => multiPartData.LocalFileName).FirstOrDefault(); //string a = uploadPath.Substring(uploadPath.LastIndexOf("PublicPictures")); //a = a.Substring(a.IndexOf("\\")); return(JsonConvert.SerializeObject(new FileResult { FileName = Path.GetFileName(_localFileName), FileLength = new FileInfo(_localFileName).Length, LocalFilePath = Cryptography.Encrypt(_localFileName), })); }
public async Task <string> UploadPrivatePicture() { HttpFileCollection filecol = HttpContext.Current.Request.Files; PictureValidation.GetInstance().CompleteValidations(filecol); string username = User.Identity.Name; string uploadPath = PictureHandling.GetInstance().HandlingUpdatePrivateDirectories(username); //var uploadPath = HttpContext.Current.Server.MapPath("~/Uploads"); // Generate a provider with a custom class, passing the path( later pass the path to base class). // This support a multipart upload. var multipartFormDataStreamProvider = new UploadMultipartFormProvider(uploadPath); // Read the MIME multipart asynchronously await Request.Content.ReadAsMultipartAsync(multipartFormDataStreamProvider); string _localFileName = multipartFormDataStreamProvider .FileData.Select(multiPartData => multiPartData.LocalFileName).FirstOrDefault(); //_localFileName = Cryptography.Decrypt(_localFileName); //Encrypt //_localFileName = Cryptography.Encrypt(_localFileName); // Create response return(JsonConvert.SerializeObject(new FileResult { FileName = Path.GetFileName(_localFileName), FileLength = new FileInfo(_localFileName).Length, LocalFilePath = Cryptography.Encrypt(_localFileName), })); }
public HttpResponseMessage DownloadPublicPicture(FileResult file) { HttpResponseMessage result = null; //string filename = "hh.jpg"; string filename = Cryptography.Decrypt(file.LocalFilePath); //filename = Path.GetFileName(filename); //filename = Path.GetFileName(filename); string path = PictureHandling.GetInstance().HandlingDownloadPublicDirectories(filename); PictureValidation.GetInstance().ValidateFileExist(path); //if (!File.Exists(path)) //{ // throw new ApiException(7779, "La imagen no existe", // System.Net.HttpStatusCode.Gone, "NoLink"); //} //else //{ // Serve the file to the client result = Request.CreateResponse(HttpStatusCode.OK); result.Content = new StreamContent(PictureHandling.GetInstance().Resize(path, file.Qualitier)); result.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment"); result.Content.Headers.ContentDisposition.FileName = filename.Substring(filename.LastIndexOf("\\") + 1, filename.Length - filename.LastIndexOf("\\") - 1); //result.Content.Headers.ContentDisposition.FileName = filename; //} return(result); }
public HttpResponseMessage DownloadPrivatePicture(FileResult file) { HttpResponseMessage result = null; string username = User.Identity.Name; string filename = Cryptography.Decrypt(file.LocalFilePath); filename = Path.GetFileName(filename); string path = PictureHandling.GetInstance().HandlingDownloadPrivateDirectories(username, filename); PictureValidation.GetInstance().ValidateFileExist(path); result = Request.CreateResponse(HttpStatusCode.OK); result.Content = new StreamContent(PictureHandling.GetInstance().Resize(path, file.Qualitier)); result.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment"); result.Content.Headers.ContentDisposition.FileName = filename; return(result); }
public string DownloadPublicPictureSrc(FileResult file) { string filename = Cryptography.Decrypt(file.LocalFilePath); string path = PictureHandling.GetInstance().HandlingDownloadPublicDirectories(filename); if (!File.Exists(filename)) { return(""); } String url = HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Host + ":" + HttpContext.Current.Request.Url.Port; Int32 indexpath = path.IndexOf("\\MyFiles\\PublicPictures\\"); String myrelativepath2 = path.Substring(indexpath); myrelativepath2 = myrelativepath2.Replace("\\", "/"); string mypath2 = url + myrelativepath2; return(mypath2); }
public async Task <string> UploadPublicPictureWithGUID() { HttpFileCollection filecol = HttpContext.Current.Request.Files; HttpPostedFile a = filecol.Get("FileUpload"); PictureValidation.GetInstance().CompleteValidations(filecol); string uploadPath = PictureHandling.GetInstance().HandlingUpdatePublicDirectories(); Guid Guided = Guid.NewGuid(); uploadPath += "\\" + Guided.ToString("N") + ".jpg"; //a.SaveAs(uploadPath); MemoryStream mss = new MemoryStream(); a.InputStream.CopyTo(mss); using (mss) { ////with no compress; //Image img = System.Drawing.Image.FromStream(ms); //img.Save(withoutextension + "-th" + ".jpg"); //with compress; Image img = System.Drawing.Image.FromStream(mss); EncoderParameters eps = new EncoderParameters(1); eps.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 90L); string mimetype = GetMimeType(new System.IO.FileInfo(uploadPath).Extension); ImageCodecInfo ici = GetEncoderInfo(mimetype); img.Save(uploadPath, ici, eps); } return(JsonConvert.SerializeObject(new FileResult { FileName = Path.GetFileName(uploadPath), FileLength = new FileInfo(uploadPath).Length, LocalFilePath = Cryptography.Encrypt(uploadPath), })); }
public async Task <string> UploadPublicPictureCompresser() { HttpFileCollection filecol = HttpContext.Current.Request.Files; PictureValidation.GetInstance().CompleteValidations(filecol); string uploadPath = PictureHandling.GetInstance().HandlingUpdatePublicDirectories(); var multipartFormDataStreamProvider = new UploadMultipartFormProvider(uploadPath); await Request.Content.ReadAsMultipartAsync(multipartFormDataStreamProvider); string _localFileName = multipartFormDataStreamProvider .FileData.Select(multiPartData => multiPartData.LocalFileName).FirstOrDefault(); string withoutextension = _localFileName.Split('.')[0]; #region Qualitier var qualitiesparam = HttpContext.Current.Request.Params["qualitier"]; Qualitiers q = JsonConvert.DeserializeObject <Qualitiers>(qualitiesparam); #endregion using (System.IO.MemoryStream ms = PictureHandling.GetInstance().Resize(_localFileName, q)) { ////with no compress; //Image img = System.Drawing.Image.FromStream(ms); //img.Save(withoutextension + "-th" + ".jpg"); //with compress; Image img = System.Drawing.Image.FromStream(ms); EncoderParameters eps = new EncoderParameters(1); eps.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 90L); string mimetype = GetMimeType(new System.IO.FileInfo(_localFileName).Extension); ImageCodecInfo ici = GetEncoderInfo(mimetype); img.Save(withoutextension + "-th" + ".jpg", ici, eps); } return(JsonConvert.SerializeObject(new FileResult { FileName = Path.GetFileName(_localFileName), FileLength = new FileInfo(_localFileName).Length, LocalFilePath = Cryptography.Encrypt(_localFileName), })); }
public string DownloadPublicPicture64(FileResult file) { HttpResponseMessage result = null; string filename = Cryptography.Decrypt(file.LocalFilePath); if (!File.Exists(filename)) { return(""); } string path = PictureHandling.GetInstance().HandlingDownloadPublicDirectories(filename); PictureValidation.GetInstance().ValidateFileExist(path); //result = Request.CreateResponse(HttpStatusCode.OK); //result.Content = new StreamContent(PictureHandling.GetInstance().Resize(path, file.Qualitier)); //result.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment"); //result.Content.Headers.ContentDisposition.FileName = filename.Substring(filename.LastIndexOf("\\") + 1, filename.Length - filename.LastIndexOf("\\") - 1); string src = Convert.ToBase64String(PictureHandling.GetInstance().Resize(path, file.Qualitier).ToArray()); return(src); }
public string DownloadPublicPictureSrcThumb(FileResult file) { #region Local string filename = Cryptography.Decrypt(file.LocalFilePath); string path = PictureHandling.GetInstance().HandlingDownloadPublicDirectories(filename); Int32 indexextensionLocal = filename.IndexOf(".jpg"); if (indexextensionLocal == -1) { indexextensionLocal = filename.IndexOf(".png"); } if (indexextensionLocal == -1) { indexextensionLocal = filename.IndexOf(".jpeg"); } if (indexextensionLocal == -1) { throw new Exception("Error con la extensión"); } String filenametoverify = filename.Insert(indexextensionLocal, "-th"); if (!File.Exists(filenametoverify)) { return(DownloadPublicPictureSrc(file)); } #endregion #region Public String url = HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Host + ":" + HttpContext.Current.Request.Url.Port; Int32 indexpath = path.IndexOf("\\MyFiles\\PublicPictures\\"); String myrelativepath2 = path.Substring(indexpath); myrelativepath2 = myrelativepath2.Replace("\\", "/"); Int32 indexextension = myrelativepath2.IndexOf(".jpg"); myrelativepath2 = myrelativepath2.Insert(indexextension, "-th"); string mypath2 = url + myrelativepath2; #endregion return(mypath2); }