Example #1
0
        public ActionResult DownloadFile(DownloadFileParam fileParam)
        {   
            foreach(var fileCheck in fileParam.ListFiles)
            {
                if (!GlobalDictionaries.Scans.Exists(x => x == fileCheck.TempFile))
                    throw new Exception("Не найден файл для скачивания!");
            }
            var tempDir = Path.GetTempPath();
            byte[] response;
            var fileId = fileParam.ListFiles[0].TempFile;
            var fileName = fileParam.ListFiles[0].FileName;
            string mimeType = null;
            
	        if (fileParam.SaveAs == (int) GlobalDictionaries.SaveAsValues.Pdf)
	        {
		        fileId = MakePdf(fileParam.ListFiles);
		        mimeType = _mimeTypes["pdf"];
				fileName = Path.ChangeExtension(fileName, ".pdf");
	        }
	        else
	        {
				var extension = Path.GetExtension(fileName);
				if (!string.IsNullOrEmpty(extension))
					mimeType = _mimeTypes[extension.Substring(1).ToLower()];
	        }
            var file = Path.Combine(tempDir, fileId);
            if (File.Exists(file))
            {
                response = File.ReadAllBytes(file);
                File.Delete(file);
                GlobalDictionaries.Scans.Remove(fileId);
                foreach (var img in fileParam.ListFiles)
                {
                    if (File.Exists(tempDir + img.TempFile))
                    {
						File.Delete(tempDir + img.TempFile);
                        GlobalDictionaries.Scans.Remove(img.TempFile);
                    }
                }
            }
            else
                response = Encoding.UTF8.GetBytes("Not found");
            return new ActionResult { Content = response, ContentType = mimeType, FileNameToDownload = fileName };
        }
Example #2
0
 public DownloadFileParam BindDownloadFile()
 {
     var downloadParam = new DownloadFileParam { ListFiles = new List<DownloadFile>()};
     var i = 0;
     while(true)
     {                
         var fileName = TryGet("fileName"+i);
         var tempFile = TryGet("fileId"+i);
         if (fileName == null || tempFile == null)
             break;
         downloadParam.ListFiles.Add(new DownloadFile(fileName,tempFile));
         i++;
     }                       
     if(downloadParam.ListFiles.Count == 0)
         throw new Exception("Нечего загружать (неверный запрос)");
     
     downloadParam.SaveAs = TryGetInt("saveAs", (int)GlobalDictionaries.SaveAsValues.Pictures);
     return downloadParam;
 }