public HttpResponseMessage DownloadPublicSpreedSheet(FileResult file) { HttpResponseMessage result = null; string filename = Cryptography.Decrypt(file.LocalFilePath); filename = Path.GetFileName(filename); string path = SpreedSheetHandling.GetInstance().HandlingDownloadPublicDirectories(filename); SpreedSheetValidation.GetInstance().ValidateFileExist(path); //if (!File.Exists(path)) //{ // throw new ApiException(7779, "La hoja de cálculo 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 DownloadPrivateSpreedSheet(FileResult file) { HttpResponseMessage result = null; string username = User.Identity.Name; string filename = Cryptography.Decrypt(file.LocalFilePath); filename = Path.GetFileName(filename); string path = SpreedSheetHandling.GetInstance().HandlingDownloadPrivateDirectories(username, filename); SpreedSheetValidation.GetInstance().ValidateFileExist(path); 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> UploadPublicSpreedSheet() { HttpFileCollection filecol = HttpContext.Current.Request.Files; SpreedSheetValidation.GetInstance().CompleteValidations(filecol); string uploadPath = SpreedSheetHandling.GetInstance().HandlingUpdatePublicDirectories(); 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), })); }