2011-02-12 3 views
0

swf를 내 aspx에로드 할 수 없습니다. 나는 데이터베이스에서 swf를 검색하고 페이지에 표시하기로되어 있습니다. 내 코드는 db에서 검색 한 후 로컬 폴더에 SWF를 만들 수 있지만 ... 다운로드 후 aspx에 자동으로 표시 할 수 없습니다 ... 그리고 aspx의 코드는 btw가되어야합니까? ... CommandBevavior.SequentialAccess를 사용하는 경우에도 SqlDataReaderFILESTREAM의 내용을 읽고 어떤 아이디어들? ... 들으 ...ASP.NET에서 SWF 파일로드

public string swfFileName = ""; 


protected void Page_Load(object sender, EventArgs e) 
{ 
    string swfToDbConnStr = ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString; 
    try 
    { 

     using (SqlConnection connection = new SqlConnection(swfToDbConnStr)) 
     { 
      // Assumes that connection is a valid SqlConnection object. 
      SqlCommand command = new SqlCommand(
       "SELECT gameStorage FROM eGame", connection); 

      // Writes the BLOB to a file (*.swf). 
      FileStream stream; 
      // Streams the BLOB to the FileStream object. 
      BinaryWriter writer; 

      // Size of the BLOB buffer. 
      int bufferSize = 100; 
      // The BLOB byte[] buffer to be filled by GetBytes. 
      byte[] outByte = new byte[bufferSize]; 
      // The bytes returned from GetBytes. 
      long retval; 
      // The starting position in the BLOB output. 
      long startIndex = 0; 



      // Open the connection and read data into the DataReader. 
      connection.Open(); 
      SqlDataReader reader = command.ExecuteReader(CommandBehavior.SequentialAccess); 

      while (reader.Read()) 
      { 


       // Create a file to hold the output. 
       stream = new FileStream(
        //"logo" + pubID + ".swf", FileMode.OpenOrCreate, FileAccess.Write); 
       "FBIS" + ".swf", FileMode.OpenOrCreate, FileAccess.Write); 
       writer = new BinaryWriter(stream); 

       // Reset the starting byte for the new BLOB. 
       startIndex = 0; 

       // Read bytes into outByte[] and retain the number of bytes returned. 
       retval = reader.GetBytes(0, startIndex, outByte, 0, bufferSize); 




       // Continue while there are bytes beyond the size of the buffer. 
       while (retval == bufferSize) 
       { 

        writer.Write(outByte); 
        writer.Flush(); 

        // Reposition start index to end of last buffer and fill buffer. 
        startIndex += bufferSize; 
        retval = reader.GetBytes(0, startIndex, outByte, 0, bufferSize); 
       } 

       // Write the remaining buffer. 
       writer.Write(outByte, 0, (int)retval - 1); 
       writer.Flush(); 

       // Close the output file. 
       writer.Close(); 
       stream.Close(); 

      } 

      // Close the reader and the connection. 
      reader.Close(); 
      connection.Close(); 
      swfFileName = Directory.GetCurrentDirectory(); 







     } 
    } 
    catch (Exception exs) { } 
} 

답변

0

은 비효율적이다. 버퍼링 된 사본을 만들고 있지만 Stream.CopyTo을 대신 사용해보십시오. SqlDataReader를 통해 스트림을 선언하는 것은 간단합니다. 바로 수행하는 샘플 코드는 Download and Upload images from SQL Server via ASP.Net MVC을 참조하십시오.

그러나 전체적으로 FILESTREAM 얼룩은 큰 내용의 경우에만 SqlFileStream을 사용하는 것이 훨씬 좋습니다. ASP.Net을 통한 대형 BLOB 다운로드 및 업로드를 포함하여 전체 샘플은 FILESTREAM MVC: Download and Upload images from SQL Server을 참조하십시오.

부수적으로이 임시 파일을 반환하기 위해 파일을 읽는 것은 액세스 빈도에 따라 상당히 비쌀 수 있습니다.

0

페이지에 SWF 파일을 표시하려면 플래시 객체가 있어야로드 할 수 있습니다. 그런 다음 플래시 객체를 ASHX 핸들러로 가리켜 야합니다.이 핸들러는 데이터베이스에서 파일을 가져 와서 반환합니다.

+0

어 ... ASHX 메서드가 작동하고 @Remus가 제안한대로 SqlFileStream을 사용하여 코드를 수정했습니다 ... 모든 도움을 얻으려면 .... – user614454