Upload photo to database?

Last post 02-11-2009, 9:01 PM by cutechat. 33 replies.
Page 1 of 2 (34 items)   1 2 Next >
Sort Posts: Previous Next
  •  08-11-2008, 4:01 PM 42892

    Upload photo to database?

    Can I upload a photo into a SQL Server 2005 photo field?  Is there an example of how to do that?
     
    Diane
  •  08-11-2008, 4:43 PM 42895 in reply to 42892

    Re: Upload photo to database?

    Diane,
     
    1. Store the content of the uploaded file in the Byte buffer.
     
    byte[] data = new byte[args.FileSize];
    using(Stream stream=args.OpenStream())
    {
        stream.Read(data,0,data.Length);
    }
     
    2. Store the buffer in the Database, and it is very easy as long as you have the database table and you know some SQL Statments.

    asp.net Chat http://cutesoft.net/ASP.NET+Chat/default.aspx
    Web Messenger: http://cutesoft.net/Web-Messenger/default.aspx
    asp.net wysiwyg editor: http://cutesoft.net/ASP.NET+WYSIWYG+Editor/default.aspx
    asp wysiwyg html editor: http://cutesoft.net/ASP
    asp.net Image Gallery: http://cutesoft.net/ASP.NET+Image+Gallery/default.aspx
    Live Support: http://cutesoft.net/live-support/default.aspx

  •  12-16-2008, 11:53 AM 46978 in reply to 42895

    Re: Upload photo to database?

    Is it possible to do this without saving the file to disc first?
  •  12-16-2008, 3:59 PM 46989 in reply to 46978

    Re: Upload photo to database?

    pat333,
     
    If you don't use the .CopyTo method to copy the uploaded files , the file will not be saved to disc first.
     
     void Uploader_FileUploaded(object sender, UploaderEventArgs args)
            {
                Uploader uploader = (Uploader)sender;
                InsertMsg("File uploaded! " + args.FileName + ", " + args.FileSize + " bytes.");
                
                //Copies the uploaded file to a new location.
                //args.CopyTo("c:""temp"""+args.FileName);
                //You can also open the uploaded file's data stream.
                //System.IO.Stream data = args.OpenStream();
            }

    asp.net Chat http://cutesoft.net/ASP.NET+Chat/default.aspx
    Web Messenger: http://cutesoft.net/Web-Messenger/default.aspx
    asp.net wysiwyg editor: http://cutesoft.net/ASP.NET+WYSIWYG+Editor/default.aspx
    asp wysiwyg html editor: http://cutesoft.net/ASP
    asp.net Image Gallery: http://cutesoft.net/ASP.NET+Image+Gallery/default.aspx
    Live Support: http://cutesoft.net/live-support/default.aspx

  •  12-17-2008, 4:30 AM 47012 in reply to 46989

    Re: Upload photo to database?

    Hi,
     
    I have an empty  FileUploaded() method and no explicit copyto anywhere but the uploader always says "unable to find the uploaded file in the directory .../UploaderTemp" on an attempted upload

    Control is just:
     
      <CuteWebUI:Uploader ID="ctlFormUpload"                                                                       
              OnFileUploaded="ctlFormUpload_FileUploaded" runat="server"
              FileTypeNotSupportMsg="Please upload only .doc or .docx files"
       >
       <validateoption maxsizekb="10240" AllowedFileExtensions="doc,docx" />
        </CuteWebUI:Uploader>
  •  12-18-2008, 8:54 AM 47082 in reply to 47012

    Re: Upload photo to database?

    Hi,
     
    Do you have a folder website/UploaderTemp , and does it has permission to write file?
     
    Please try this way , maybe you can get error details:
     
    <CuteWebUI:Uploader ID="ctlFormUpload"                                                                       
              OnFileUploaded="ctlFormUpload_FileUploaded" runat="server"
              FileTypeNotSupportMsg="Please upload only .doc or .docx files"
              UploadType="IFrame"
       >
     
    Regards,
    Terry
     
  •  12-18-2008, 9:35 AM 47087 in reply to 47082

    Re: Upload photo to database?

    No. I don't want to store the file to disc - I want to upload directly to database without saving to disc (this is an environment where we don't have any disc write permissions).
  •  12-18-2008, 11:00 AM 47090 in reply to 47087

    Re: Upload photo to database?

    Hi,
     
    In that case you need use another 'UploaderProvider' , and register the class name to web.config appSettings:
     
    <add key="CuteWebUI.AjaxUploader.Provider" name="UploaderDatabaseProvider.UploaderSqlServerProvider,UploaderDatabaseProvider"/>
     
    Here is the provider implementation code :
     
    -old code deleted-see other reply- 
     
    Regards,
    Terry
     
     
  •  12-18-2008, 11:16 AM 47098 in reply to 47090

    Re: Upload photo to database?

    Great thanks will give this a go.
  •  01-05-2009, 4:31 AM 47399 in reply to 47090

    Re: Upload photo to database?

    Hi
     
    I got this working great with a single upload but is it possible to do this with multiple uploads enabled? That seems to require at least the AppendData method which isn't supplied in the code.
  •  01-05-2009, 7:59 PM 47430 in reply to 47399

    Re: Upload photo to database?

    Hi,
     
    Oh yes.
    Since we changed the uploader recently ,
    we forgot to implement this sample method.
     
    the AppendData method should be:
     
    -old code deleted-see the following reply-
     
    Please test it and reply me if you get more problem.
     
     
    Regards,
    Terry.
  •  01-15-2009, 6:35 PM 47795 in reply to 47430

    Re: Upload photo to database?

    Thanks. I am testing this now and it seems to cut files off at 65536 bytes. It apparently uploads fine (no errors, progress goes to 100%) but when looking at what's in the database table, all files uploaded greater than 65536 bytes are reporting just that amount in filesize column. Anything smaller than this is working fine. Is there a configuration setting I'm missing?
  •  01-15-2009, 7:10 PM 47796 in reply to 47795

    Re: Upload photo to database?

    On investigation, it's only doing this when uploadtype="auto" which I think in this case is silverlight. If I manually set the uploadtype to either iframe or flash, it works ok?
  •  01-15-2009, 9:38 PM 47799 in reply to 47796

    Re: Upload photo to database?

    Hi,
     
    -old code deleted-
     
    Regards,
    Terry
  •  01-16-2009, 4:21 AM 47803 in reply to 47799

    Re: Upload photo to database?

    Thanks, that seems to have fixed the problem.
  •  01-16-2009, 11:38 AM 47818 in reply to 47803

    Re: Upload photo to database?

    Actually, sorry - the file size is reporting correct but the larger files are being corrupted when in silverlight mode. Other modes work ok.
  •  01-30-2009, 6:08 AM 48222 in reply to 47818

    Re: Upload photo to database?

    We have still not managed to get this working.
     
    For all larger files (small files work in all modes) :
     
    - In silverlight mode, uploads go up without error but are corrupted.
    - In flash mode, get the message "unable to find the file in custom provider"
    - In iframe mode get message 'cannot access uploadtemp'
     
    This is in multiple or single upload mode. Please help.
     

     
     
     
     
  •  02-03-2009, 2:08 AM 48280 in reply to 48222

    Re: Upload photo to database?

    Hi,
     
    Please check this code , we have already tested it :
     
     
    The old issue is that the offset of append data is wrong. Sorry for the inconvenience.
     
    Regards,
    Terry
     
     
  •  02-03-2009, 2:16 AM 48281 in reply to 48280

    Re: Upload photo to database?

    Web.config :
     
     <add key="UploaderDatabase" value="server=(local);database=UploaderSamples;uid=test;pwd=test"/>
     <add key="CuteWebUI.AjaxUploader.Provider" value="UploaderDatabaseProvider.UploaderSqlServerProvider,App_Code"/>
     
    Sql Schema:
     

    if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[AjaxUploaderTempFiles]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
    drop table [dbo].[AjaxUploaderTempFiles]
    GO

    CREATE TABLE [dbo].[AjaxUploaderTempFiles] (
     [FileGuid] [uniqueidentifier] NOT NULL ,
     [FileTime] [datetime] NOT NULL ,
     [FileName] [nvarchar] (255)
     [FileSize] [int] NOT NULL ,
     [FileData] [image] NOT NULL ,
     [IsPersist] [bit] NOT NULL
    ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
    GO

    ALTER TABLE [dbo].[AjaxUploaderTempFiles] WITH NOCHECK ADD
     CONSTRAINT [PK_AjaxUploaderTempFiles] PRIMARY KEY  CLUSTERED
     (
      [FileGuid]
     )  ON [PRIMARY]
    GO
     
     
     
     
     
  •  02-03-2009, 5:29 AM 48290 in reply to 48281

    Re: Upload photo to database?


    With your updated code this is working in silverlight mode now (for files that weren't before), but not in flash or iframe mode. In flash mode, get the message "cannot find the file in custom provider" and iframe get the message "Access to the path C:\....\UploaderTemp is denied"
     
Page 1 of 2 (34 items)   1 2 Next >
View as RSS news feed in XML