양식을 통해 파일을 업로드 한 다음 SQL에 BLOB 형식으로 저장하려고합니다.ASP MVC 2 (blob) 데이터베이스에 파일 업로드
난 이미 내 데이터베이스가 완전히 덩어리를 취할 수 있으며, 나는 로컬 디렉토리에 저장, 파일을 컨트롤러를 가지고 내 양식이 잘 작동이 모든 내가 놓친 거지 이제
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult FileUpload(int id, HttpPostedFileBase uploadFile)
{
//allowed types
string typesNonFormatted = "text/plain,application/msword,application/pdf,image/jpeg,image/png,image/gif";
string[] types = typesNonFormatted.Split(',');
//
//Starting security check
//checking file size
if (uploadFile.ContentLength == 0 && uploadFile.ContentLength > 10000000)
ViewData["StatusMsg"] = "Could not upload: File too big (max size 10mb) or error while transfering the file.";
//checking file type
else if(types.Contains(uploadFile.ContentType) == false)
ViewData["StatusMsg"] = "Could not upload: Illigal file type!<br/> Allowed types: images, Ms Word documents, PDF, plain text files.";
//Passed all security checks
else
{
string filePath = Path.Combine(HttpContext.Server.MapPath("../Uploads"),
Path.GetFileName(uploadFile.FileName)); //generating path
uploadFile.SaveAs(filePath); //saving file to final destination
ViewData["StatusMsg"] = "Uploaded: " + uploadFile.FileName + " (" + Convert.ToDecimal(uploadFile.ContentLength)/1000 + " kb)";
//saving file to database
//
//MISSING
}
return View("FileUpload", null);
}
파일을 데이터베이스에 저장 중입니다. 주제에 대해 아무 것도 찾을 수 없었습니다 ... 정규 웹 사이트에서는 할 수있는 방법을 찾았지만 MVC2에서는 찾지 못했습니다.
모든 종류의 도움을 환영합니다!
감사합니다.
감사합니다 (그런데 IW_Attachment 내 데이터베이스 테이블 중 하나의 이름입니다) , 나는 그것에게 시도를주고, 당신에게 알릴 것이다. 감사! –
글쎄, 실제로는 꽤 쉬웠다. –