파일 업로드 페이지에 AsyncFileUpload 컨트롤이 있습니다. 사용자가 파일을 탐색하면 업로드 컨트롤이 파일을 메모리로 가져옵니다. 그런 다음 파일을 데이터베이스에 저장하는 다음 코드를 실행하는 업로드 단추가 있습니다.Ajax AsyncFileUpload.FileBytes returns null
파일이 약 500KB 이상이면 컨트롤의 FileBytes 속성이 null을 단순히 반환한다는 것을 알았습니다. 이것은 내 서버에서 발생하지만 로컬에서 응용 프로그램을 실행할 때 정상적으로 실행됩니다.
데이터베이스에 파일을 커밋하기 전에 추가 정보를 작성하려면 사용자에게 문의해야하므로 OnUploadCompleted 이벤트를 처리하지 않습니다.
내 Web.config의이 있습니다 httpRuntime을 maxRequestLength의 = "10000"/>
private void UploadDocument(int mietID)
{
if (Page.IsValid)
{
if (mietID > 0)
{
if (File1.HasFile && File1.FileBytes != null)
{
string[] docFormats = MIETPConfig.Current.SupportedDocumentFormats;
for (short i = 0; i < docFormats.Length; i++)
docFormats[i] = docFormats[i].ToUpper();
if (docFormats.Contains(Path.GetExtension(File1.FileName).ToUpper()))
{
try
{
byte[] uploadedBytes = File1.FileBytes;
DocumentController.CreateDocument(txtLinkText.Text, Path.GetFileName(File1.PostedFile.FileName), uploadedBytes, mietID, (User)Session["User"]);
MietpClientScripts.CloseWindow(Page);
}
catch (Exception)
{
lblUploadStatus.Text = "There was an error saving the document to the database.";
}
}
else
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
foreach (string s in docFormats)
sb.Append(s + ", ");
sb.Remove(sb.Length - 2, 2);
lblUploadStatus.Text = "Invalid file format, only these formats are supported: " + sb.ToString();
}
}
else
{
lblUploadStatus.Text = "There was an error saving the document, the document could not be read; it might be too large to upload.";
}
}
else
lblUploadStatus.Text = "No Mietp ID to associate document with.";
}
}
죄송합니다. 게시물의 내용을 놓쳐 버렸습니다. maxRequestLength를 10000으로 설정했지만 102400으로 시도했습니다. FileContent에서 스트림을 사용해 보았지만 Length 속성이 올바른 바이트 수를 제공하더라도 읽기 메서드는 아무 것도 반환하지 않습니다. File.SaveAs는 FileBytes가 null 일 때마다 ObjectDisposedException을 제공합니다 (닫힌 파일에 액세스 할 수 없음). –
다음과 같이하면 :'void UploadDocument() {File1.SaveAs (Server.MapPath ("~/myuploadedfile.tmp")); }', 지금 모든 논리 대신; 이 파일을 올바르게 저장합니까? 그렇지 않다면, AJAX 대신에 보통'FileUpload'를 사용할 때 작동합니까? –
아니요, 로직을 제거한 후에도 파일이 저장되지 않습니다. 필자는 FileUpload 컨트롤에 대한 직선 스왑을 수행했으며 모든 문서에서 15MB 크기의 문서를 사용할 때도 정상적으로 작동합니다. –