Storage provider and Upload provider

Last post 10-05-2012, 9:54 PM by cutechat. 10 replies.
Sort Posts: Previous Next
  •  09-24-2012, 4:28 PM 74747

    Storage provider and Upload provider

    Does the new version support custom file storage providers like version 6.6? (see this demo and source code for example)

    Does the new version support custom upload providers like version 6.6? (see this article and this article for example)

    I was able to configure custom providers in version 6.6 like so:

    1. myHtmlEditor.Setting["InsertTemplate-CuteEditorFileStorageType"] = typeof(MyTemplateFileStorage).AssemblyQualifiedName; 
    2. myHtmlEditor.Setting["InsertImage-CuteEditorFileStorageType"] = typeof(MyBlobFileStorage).AssemblyQualifiedName; 
    3. myHtmlEditor.Setting["SelectImage-CuteEditorFileStorageType"] = typeof(MyBlobFileStorage).AssemblyQualifiedName; 
    4. myHtmlEditor.Setting["InsertDocument-CuteEditorFileStorageType"] = typeof(MyBlobFileStorage).AssemblyQualifiedName; 
    5. myHtmlEditor.Setting["SelectFile-CuteEditorFileStorageType"] = typeof(MyBlobFileStorage).AssemblyQualifiedName; 
    but I can't figure out how to do this in version 8.

  •  09-25-2012, 2:55 AM 74753 in reply to 74747

    Re: Storage provider and Upload provider

    RTE8.0 provides both Sql File Provider and Local File Provider

     

    The following code shows how to use SqlFileProvider in 8.0 

      

    1.             Editor1.SetSecurity("*""*""FileProviderType"typeof(SqlFileProvider).AssemblyQualifiedName);  
    2.             Editor1.SetSecurity("*""*""StoragePath""/");  
    3.             Editor1.SetSecurity("*""*""FileProviderArg0""download.ashx?file=");  

    This is the sqlfileprovider example codes   /rte-uploads/members/166648/zip/sqlfileprovider.zip, there is a  sql scripts file to create the File Storage Table, please run it in your database  first

  •  09-25-2012, 7:46 AM 74759 in reply to 74753

    Re: Storage provider and Upload provider

    Thanks Jeff. But what about the upload provider? Can we also define a custom upload provider?

     

    Finally, your code example shows how to set one custom file provider but can we define one provider for files, one for images and one for templates like we could in v6.6? If so, how?

  •  09-25-2012, 12:37 PM 74762 in reply to 74759

    Re: Storage provider and Upload provider

    frJericho,

     

    Please wait 1 or 2 days.

     

    I will publish a full example.

     

    Adam

    CuteSoft


    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

  •  09-26-2012, 6:26 AM 74770 in reply to 74759

    Re: Storage provider and Upload provider

    http://www.richtexteditor.com/download.aspx

     

    Please download the new file provider example. We will create the upload provider soon.


    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

  •  09-26-2012, 9:12 AM 74777 in reply to 74770

    Re: Storage provider and Upload provider

    Thank you Adam. I'll check back later for the upload provider.
  •  10-04-2012, 3:16 PM 74859 in reply to 74777

    Re: Storage provider and Upload provider

    Adam,

     

    can you give me an update on the upload provider sample?

     

    Thanks 

  •  10-04-2012, 8:26 PM 74860 in reply to 74859

    Re: Storage provider and Upload provider

    Hi,

     

    In the download page , there's an item

     

    RichTextEditor custom file storage example

    This download package contains the examples show how to create a custom file storage in your solutions. You can easily use a Sql Server database or access database as the file storage.

    8.0.0.0

    7.7MB

    download

     

    you can try it.

     

    If that is not fit for you , can you reply what you expect on the sample ?

     

    We can do better if we get your ideas,

     

    Thanks.

     

    Regards,

    Terry

     

  •  10-04-2012, 11:11 PM 74861 in reply to 74859

    Re: Storage provider and Upload provider

    Here is the code for uploader provider :

     

    1. using System;  
    2. using System.Data;  
    3. using System.Data.SqlClient;  
    4. using RTE;  
    5. namespace UploaderDatabaseProvider  
    6. {  
    7.     /// <summary>  
    8.     /// UploaderSqlServerProvider  
    9.     /// </summary>  
    10.     public class UploaderSqlServerProvider : RTE.UploaderProvider  
    11.     {  
    12.         const int BUFFERSIZE = 204800;  
    13.         SqlConnection _conn;  
    14.         public override void Init(IAjaxUploader uploader, System.Web.HttpContext context)  
    15.         {  
    16.             string connectionstring = System.Configuration.ConfigurationSettings.AppSettings["UploaderDatabase"];  
    17.             if (connectionstring == nullthrow (new Exception("appSettings:UploaderDatabase not found."));  
    18.             _conn = new SqlConnection(connectionstring);  
    19.             _conn.Open();  
    20.         }  
    21.         public override void Dispose()  
    22.         {  
    23.             if (_conn != null)  
    24.                 _conn.Close();  
    25.             base.Dispose();  
    26.         }  
    27.         private SqlCommand CreateCommand(string commandtext)  
    28.         {  
    29.             if (_conn == nullthrow (new Exception("Not init yet."));  
    30.             SqlCommand cmd = new SqlCommand();  
    31.             cmd.Connection = _conn;  
    32.             cmd.CommandText = commandtext;  
    33.             return cmd;  
    34.         }  
    35.         public override bool SupportFS  
    36.         {  
    37.             get  
    38.             {  
    39.                 return false;  
    40.             }  
    41.         }  
    42.         public override string GetFSPath(Guid guid)  
    43.         {  
    44.             throw (new NotSupportedException());  
    45.         }  
    46.         public override void Maintain()  
    47.         {  
    48.             SqlCommand cmd = CreateCommand("DELETE [AjaxUploaderTempFiles] WHERE FileTime<@Time");  
    49.             cmd.Parameters.Add("@Time", SqlDbType.DateTime).Value = DateTime.Now.AddHours(-1);  
    50.             cmd.ExecuteNonQuery();  
    51.         }  
    52.         public override bool GetInfo(Guid guid, out string filename, out int filesize, out bool persist)  
    53.         {  
    54.             SqlCommand cmd = CreateCommand("SELECT [FileName],[FileSize],[IsPersist] FROM [AjaxUploaderTempFiles] WHERE FileGuid=@Guid");  
    55.             cmd.Parameters.Add("@Guid", SqlDbType.UniqueIdentifier).Value = guid;  
    56.             using (SqlDataReader reader = cmd.ExecuteReader())  
    57.             {  
    58.                 if (reader.Read())  
    59.                 {  
    60.                     filename = reader.GetString(0);  
    61.                     filesize = reader.GetInt32(1);  
    62.                     persist = reader.GetBoolean(2);  
    63.                     return true;  
    64.                 }  
    65.                 else  
    66.                 {  
    67.                     filename = null;  
    68.                     filesize = 0;  
    69.                     persist = false;  
    70.                     return false;  
    71.                 }  
    72.             }  
    73.         }  
    74.         public override void Delete(Guid guid)  
    75.         {  
    76.             SqlCommand cmd = CreateCommand("DELETE [AjaxUploaderTempFiles] WHERE FileGuid=@Guid");  
    77.             cmd.Parameters.Add("@Guid", SqlDbType.UniqueIdentifier).Value = guid;  
    78.             cmd.ExecuteNonQuery();  
    79.         }  
    80.         public override void Persist(Guid guid)  
    81.         {  
    82.             SqlCommand cmd = CreateCommand("UPDATE [AjaxUploaderTempFiles] SET IsPersist=1 WHERE FileGuid=@Guid");  
    83.             cmd.Parameters.Add("@Guid", SqlDbType.UniqueIdentifier).Value = guid;  
    84.             cmd.ExecuteNonQuery();  
    85.         }  
    86.         public override void UnPersist(Guid guid)  
    87.         {  
    88.             SqlCommand cmd = CreateCommand("UPDATE [AjaxUploaderTempFiles] SET IsPersist=0 WHERE FileGuid=@Guid");  
    89.             cmd.Parameters.Add("@Guid", SqlDbType.UniqueIdentifier).Value = guid;  
    90.             cmd.ExecuteNonQuery();  
    91.         }  
    92.         public override void Save(Guid guid, string filename, System.IO.Stream stream)  
    93.         {  
    94.             int stepsize = BUFFERSIZE;  
    95.             long filesize = stream.Length;  
    96.             byte[] data = new byte[Math.Min(stepsize, filesize)];  
    97.             stream.Read(data, 0, data.Length);  
    98.             SqlCommand cmd = CreateCommand("INSERT INTO [AjaxUploaderTempFiles] ([FileGuid],[FileTime],[FileName],[FileSize],[FileData],[IsPersist]) VALUES (@Guid,@Time,@Name,@Size,@Data,0)");  
    99.             cmd.Parameters.Add("@Guid", SqlDbType.UniqueIdentifier).Value = guid;  
    100.             cmd.Parameters.Add("@Time", SqlDbType.DateTime).Value = DateTime.Now;//for Maintain  
    101.             cmd.Parameters.Add("@Name", SqlDbType.NVarChar, 255).Value = filename;  
    102.             cmd.Parameters.Add("@Size", SqlDbType.Int).Value = filesize;  
    103.             cmd.Parameters.Add("@Data", SqlDbType.Image).Value = data;  
    104.             cmd.ExecuteNonQuery();  
    105.             if (filesize <= stepsize)  
    106.                 return;  
    107.             int sentsize = stepsize;  
    108.             try  
    109.             {  
    110.                 while (true)  
    111.                 {  
    112.                     int readsize = stream.Read(data, 0, data.Length);  
    113.                     if (readsize <= 0)  
    114.                         return;  
    115.                     cmd = CreateCommand("DECLARE @ptrval binary(16) ; SELECT @ptrval = TEXTPTR([FileData]) FROM [AjaxUploaderTempFiles] WHERE [FileGuid]=@Guid ; UPDATETEXT [AjaxUploaderTempFiles].[FileData] @ptrval "  
    116.                     + sentsize + " 0 @Data");  
    117.                     cmd.Parameters.Add("@Guid", SqlDbType.UniqueIdentifier).Value = guid;  
    118.                     if (readsize != data.Length)  
    119.                     {  
    120.                         byte[] newdata = new byte[readsize];  
    121.                         Buffer.BlockCopy(data, 0, newdata, 0, readsize);  
    122.                         data = newdata;  
    123.                     }  
    124.                     cmd.Parameters.Add("@Data", SqlDbType.Image).Value = data;  
    125.                     cmd.ExecuteNonQuery();  
    126.                     sentsize += readsize;  
    127.                 }  
    128.             }  
    129.             catch (Exception)  
    130.             {  
    131.                 Delete(guid);  
    132.                 throw;  
    133.             }  
    134.         }  
    135.         public override void AppendData(Guid guid, string filename, System.IO.Stream stream)  
    136.         {  
    137.             int stepsize = BUFFERSIZE;  
    138.             long filesize = stream.Length;  
    139.             byte[] data = new byte[stepsize];  
    140.             SqlCommand cmd = CreateCommand("SELECT [FileSize] FROM [AjaxUploaderTempFiles] WHERE [FileGuid]=@Guid ; UPDATE [AjaxUploaderTempFiles] SET [FileSize]=[FileSize]+@Size WHERE [FileGuid]=@Guid");  
    141.             cmd.Parameters.Add("@Size", SqlDbType.Int).Value = filesize;  
    142.             cmd.Parameters.Add("@Guid", SqlDbType.UniqueIdentifier).Value = guid;  
    143.             int sentsize = Convert.ToInt32(cmd.ExecuteScalar());  
    144.             try  
    145.             {  
    146.                 while (true)  
    147.                 {  
    148.                     int readsize = stream.Read(data, 0, data.Length);  
    149.                     if (readsize <= 0)  
    150.                         break;  
    151.                     cmd = CreateCommand("DECLARE @ptrval binary(16) ; SELECT @ptrval = TEXTPTR([FileData]) FROM [AjaxUploaderTempFiles] WHERE [FileGuid]=@Guid ; UPDATETEXT [AjaxUploaderTempFiles].[FileData] @ptrval "  
    152.                     + sentsize + " 0 @Data");  
    153.                     cmd.Parameters.Add("@Guid", SqlDbType.UniqueIdentifier).Value = guid;  
    154.                     if (readsize != data.Length)  
    155.                     {  
    156.                         byte[] newdata = new byte[readsize];  
    157.                         Buffer.BlockCopy(data, 0, newdata, 0, readsize);  
    158.                         data = newdata;  
    159.                     }  
    160.                     cmd.Parameters.Add("@Data", SqlDbType.Image).Value = data;  
    161.                     cmd.ExecuteNonQuery();  
    162.                     sentsize += readsize;  
    163.                 }  
    164.             }  
    165.             catch (Exception)  
    166.             {  
    167.                 Delete(guid);  
    168.                 throw;  
    169.             }  
    170.         }  
    171.         public override System.IO.Stream OpenStream(Guid guid)  
    172.         {  
    173.             SqlCommand cmd = CreateCommand("SELECT DATALENGTH([FileData]) FROM [AjaxUploaderTempFiles] WHERE FileGuid=@Guid");  
    174.             cmd.Parameters.Add("@Guid", SqlDbType.UniqueIdentifier).Value = guid;  
    175.             object val = cmd.ExecuteScalar();  
    176.             if (val == null || Convert.IsDBNull(val))  
    177.                 throw (new Exception("File not found."));  
    178.             int filesize = Convert.ToInt32(val);  
    179.             int stepsize = BUFFERSIZE;  
    180.             if (filesize <= stepsize)  
    181.             {  
    182.                 cmd = CreateCommand("SELECT [FileData] FROM [AjaxUploaderTempFiles] WHERE FileGuid=@Guid");  
    183.                 cmd.Parameters.Add("@Guid", SqlDbType.UniqueIdentifier).Value = guid;  
    184.                 using (SqlDataReader reader = cmd.ExecuteReader())  
    185.                 {  
    186.                     if (reader.Read())  
    187.                     {  
    188.                         byte[] data = (byte[])reader.GetValue(0);  
    189.                         return new System.IO.MemoryStream(data);  
    190.                     }  
    191.                 }  
    192.                 throw (new Exception("File not found."));  
    193.             }  
    194.             ReadStream readstream = new ReadStream();  
    195.             readstream.provider = this;  
    196.             readstream.guid = guid;  
    197.             readstream.filesize = filesize;  
    198.             return readstream;  
    199.         }  
    200.         class ReadStream : System.IO.Stream  
    201.         {  
    202.             public UploaderSqlServerProvider provider;  
    203.             public Guid guid;  
    204.             public int filesize;  
    205.             long pos = 0;  
    206.             byte[] _tempbuff = null;  
    207.             long _tempstart = -1;  
    208.             public override long Length  
    209.             {  
    210.                 get  
    211.                 {  
    212.                     return filesize;  
    213.                 }  
    214.             }  
    215.             public override long Position  
    216.             {  
    217.                 get  
    218.                 {  
    219.                     return pos;  
    220.                 }  
    221.                 set  
    222.                 {  
    223.                     if (value < 0) throw (new ArgumentOutOfRangeException("Position"));  
    224.                     if (value >= filesize) throw (new ArgumentOutOfRangeException("Position"));  
    225.                     pos = value;  
    226.                     _tempbuff = null;  
    227.                     _tempstart = -1;  
    228.                 }  
    229.             }  
    230.             public override int Read(byte[] buffer, int offset, int count)  
    231.             {  
    232.                 int readsize = 0;  
    233.                 while (true)  
    234.                 {  
    235.                     if (_tempstart != -1 && _tempbuff != null)  
    236.                     {  
    237.                         int start = (int)(pos - _tempstart);  
    238.                         if (start >= 0 && start < _tempbuff.Length)  
    239.                         {  
    240.                             int copysize = Math.Min(count, _tempbuff.Length - start);  
    241.                             Buffer.BlockCopy(_tempbuff, start, buffer, offset, copysize);  
    242.                             pos += copysize;  
    243.                             readsize += copysize;  
    244.                             offset += copysize;  
    245.                             count -= copysize;  
    246.                             if (count <= 0)  
    247.                                 return readsize;  
    248.                         }  
    249.                     }  
    250.                     if (pos >= filesize)  
    251.                         return readsize;  
    252.                     using (SqlCommand cmd = provider.CreateCommand("DECLARE @ptrval binary(16) ; SELECT @ptrval = TEXTPTR([FileData]) FROM [AjaxUploaderTempFiles] WHERE [FileGuid]=@Guid ; READTEXT [AjaxUploaderTempFiles].[FileData] @ptrval "  
    253.                     + pos + " " + Math.Min(BUFFERSIZE, filesize - pos)))  
    254.                     {  
    255.                         cmd.Parameters.Add("@Guid", SqlDbType.UniqueIdentifier).Value = guid;  
    256.                         _tempbuff = (byte[])cmd.ExecuteScalar();  
    257.                         _tempstart = pos;  
    258.                     }  
    259.                 }  
    260.                 //return readsize;  
    261.             }  
    262.             public override bool CanRead  
    263.             {  
    264.                 get  
    265.                 {  
    266.                     return true;  
    267.                 }  
    268.             }  
    269.             public override bool CanWrite  
    270.             {  
    271.                 get  
    272.                 {  
    273.                     return false;  
    274.                 }  
    275.             }  
    276.             public override bool CanSeek  
    277.             {  
    278.                 get  
    279.                 {  
    280.                     return true;  
    281.                 }  
    282.             }  
    283.             public override void Close()  
    284.             {  
    285.             }  
    286.             public override void Flush()  
    287.             {  
    288.             }  
    289.             public override long Seek(long offset, System.IO.SeekOrigin origin)  
    290.             {  
    291.                 long oldpos = pos;  
    292.                 if (origin == System.IO.SeekOrigin.Begin)  
    293.                 {  
    294.                     Position = offset;  
    295.                 }  
    296.                 if (origin == System.IO.SeekOrigin.Current)  
    297.                 {  
    298.                     Position += offset;  
    299.                 }  
    300.                 if (origin == System.IO.SeekOrigin.End)  
    301.                 {  
    302.                     Position = filesize + offset;  
    303.                 }  
    304.                 return oldpos;  
    305.             }  
    306.             public override void SetLength(long value)  
    307.             {  
    308.                 throw (new NotSupportedException());  
    309.             }  
    310.             public override void Write(byte[] buffer, int offset, int count)  
    311.             {  
    312.                 throw (new NotSupportedException());  
    313.             }  
    314.         }  
    315.     }  
    316. }  
     

     

    1. if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[AjaxUploaderTempFiles]'and OBJECTPROPERTY(id, N'IsUserTable') = 1)  
    2. drop table [dbo].[AjaxUploaderTempFiles]  
    3. GO  
    4. CREATE TABLE [dbo].[AjaxUploaderTempFiles] (  
    5.  [FileGuid] [uniqueidentifier] NOT NULL ,  
    6.  [FileTime] [datetime] NOT NULL ,  
    7.  [FileName] [nvarchar] (255),  
    8.  [FileSize] [intNOT NULL ,  
    9.  [FileData] [image] NOT NULL ,  
    10.  [IsPersist] [bitNOT NULL   
    11. ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]  
    12. GO  
    13. ALTER TABLE [dbo].[AjaxUploaderTempFiles] WITH NOCHECK ADD   
    14.  CONSTRAINT [PK_AjaxUploaderTempFiles] PRIMARY KEY  CLUSTERED   
    15.  (  
    16.   [FileGuid]  
    17.  )  ON [PRIMARY]   
    18. GO  

     

    1. <?xml version="1.0"?>  
    2. <configuration>  
    3.     <appSettings>  
    4.   
    5.         <add key="RTE.ImageEditor.TempFolder" value="~/rtetemp"/>  
    6.   
    7.         <add key="UploaderDatabase" value="server=(local);database=rtedb;uid=test;pwd=test"/>  
    8.         <add key="RTE.AjaxUploader.Provider" value="UploaderDatabaseProvider.UploaderSqlServerProvider,App_Code"/>  
    9.           
    10.     </appSettings>  
    11.     <connectionStrings/>  
    12.     <system.web>  
    13.         <customErrors mode="Off" />  
    14.         <pages validateRequest="true" enableViewStateMac="true" enableEventValidation="false" viewStateEncryptionMode="Always"   />  
    15.         <compilation debug="true">  
    16.             <assemblies>  
    17.                 <add assembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/></assemblies></compilation>  
    18.         <authentication mode="None"/>  
    19.         <httpModules>  
    20.             <add name="UploadModule" type="RTE.UploadModule,RichTextEditor"/>  
    21.         </httpModules>  
    22.     </system.web>  
    23. </configuration>  

     

    Regards,
    Terry

     

  •  10-05-2012, 7:36 AM 74867 in reply to 74861

    Re: Storage provider and Upload provider

    Thanks for the sample code for upload provider.

     

    My only outstanding question is how can I specify a different provider for templates and images. Here's how I do it in 6.6:

    1. myHtmlEditor.Setting["InsertTemplate-CuteEditorFileStorageType"] = typeof(MyTemplateFileStorage).AssemblyQualifiedName;   
    2. myHtmlEditor.Setting["InsertImage-CuteEditorFileStorageType"] = typeof(MyBlobFileStorage).AssemblyQualifiedName;   

     

    As you can see I have "MyTemplateFileStorage" and "MyBlobFileStorage".
  •  10-05-2012, 9:54 PM 74874 in reply to 74867

    Re: Storage provider and Upload provider

    Hi, 

     

    try this :

     

    Editor1.SetSecurity("Gallery,Image""*""FileProviderType"typeof(SqlFileProvider).AssemblyQualifiedName);

     

    the first parameter specified the categories which you want to apply the security setting .

     

    "*" means all , "Gallery" means insertgallery dialog with thumbnails , "Image" means  the simple file dialog for images

     

    The predefined categories are 

     

    Gallery,Image,Video,Document,Template 

     

    check this about the configuration : http://richtexteditor.com/document/scr/html/image-gallery-path.htm 

     

    Regards,

    Terry

     

View as RSS news feed in XML