Uploading to database

Nov 23, 2010 at 8:29 PM

Hello, i was wondering if i would be able to use this control to upload to a database?

May 20, 2011 at 12:55 PM

You can. Create a custom adapter and override the processfile method.

Sep 8, 2011 at 5:44 PM
Edited Sep 8, 2011 at 5:44 PM

 

First this is a fantastic control.  Big kudos to the author.  

I just wrote an object that does the IO to the database and file system simultaneously.  

 

    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>

            <fjx:FileUploader ID="FileUploader1" runat="server" OnFileReceived="fileUploader_FileReceived">
                <Adapters>
                    <fjx:FileSaverAdapter FolderName="Folder1"></fjx:FileSaverAdapter>
                </Adapters>
            </fjx:FileUploader>

        </ContentTemplate>
    </asp:UpdatePanel>

Code Behind:  

        protected void fileUploader_FileReceived(object sender, com.flajaxian.FileReceivedEventArgs e)
        {
            Model.PhyleLogic myPhyleLogic = new Model.PhyleLogic();
           
            int imgLength = e.File.ContentLength;
            string sExtension = System.IO.Path.GetExtension(e.File.FileName).ToLower();

            // Create a byte to hold the data and give it the length
            byte[] imgBinaryData = new byte[imgLength];
            e.File.InputStream.Read(imgBinaryData, 0, imgLength); // Read it into a stream (int)

            myPhyleLogic.FileName = e.File.FileName.ToLower();
            myPhyleLogic.FileContentType = "application/" + sExtension;
            myPhyleLogic.FileContent = imgBinaryData;

            int newFileId = myPhyleLogic.Insert();// new record ID number

        }

 

PhyleLogic is the name of the class I created for the database interaction.  Sounded like fun on a Thursday :p

Data Table has only four columns; FileId, FileName, FileContentType, FileContent  Pretty simple.  

I hope this helps.