|
Storage provider and Upload provider
Last post 10-05-2012, 9:54 PM by cutechat. 10 replies.
-
09-24-2012, 4:28 PM |
-
frJericho
-
-
-
Joined on 05-02-2010
-
-
Posts 169
-
-
|
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: - myHtmlEditor.Setting["InsertTemplate-CuteEditorFileStorageType"] = typeof(MyTemplateFileStorage).AssemblyQualifiedName;
- myHtmlEditor.Setting["InsertImage-CuteEditorFileStorageType"] = typeof(MyBlobFileStorage).AssemblyQualifiedName;
- myHtmlEditor.Setting["SelectImage-CuteEditorFileStorageType"] = typeof(MyBlobFileStorage).AssemblyQualifiedName;
- myHtmlEditor.Setting["InsertDocument-CuteEditorFileStorageType"] = typeof(MyBlobFileStorage).AssemblyQualifiedName;
- 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 |
-
Jeff
-
-
-
Joined on 02-22-2011
-
-
Posts 126
-
-
|
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
- Editor1.SetSecurity("*", "*", "FileProviderType", typeof(SqlFileProvider).AssemblyQualifiedName);
- Editor1.SetSecurity("*", "*", "StoragePath", "/");
- 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 |
-
frJericho
-
-
-
Joined on 05-02-2010
-
-
Posts 169
-
-
|
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 |
-
09-26-2012, 6:26 AM |
-
09-26-2012, 9:12 AM |
-
frJericho
-
-
-
Joined on 05-02-2010
-
-
Posts 169
-
-
|
Re: Storage provider and Upload provider
Thank you Adam. I'll check back later for the upload provider.
|
|
-
10-04-2012, 3:16 PM |
-
frJericho
-
-
-
Joined on 05-02-2010
-
-
Posts 169
-
-
|
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 |
-
cutechat
-
-
-
Joined on 07-22-2004
-
-
Posts 2,332
-
-
|
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
|
|
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 |
-
cutechat
-
-
-
Joined on 07-22-2004
-
-
Posts 2,332
-
-
|
Re: Storage provider and Upload provider
Here is the code for uploader provider : - using System;
- using System.Data;
- using System.Data.SqlClient;
- using RTE;
- namespace UploaderDatabaseProvider
- {
-
-
-
- public class UploaderSqlServerProvider : RTE.UploaderProvider
- {
- const int BUFFERSIZE = 204800;
- SqlConnection _conn;
- public override void Init(IAjaxUploader uploader, System.Web.HttpContext context)
- {
- string connectionstring = System.Configuration.ConfigurationSettings.AppSettings["UploaderDatabase"];
- if (connectionstring == null) throw (new Exception("appSettings:UploaderDatabase not found."));
- _conn = new SqlConnection(connectionstring);
- _conn.Open();
- }
- public override void Dispose()
- {
- if (_conn != null)
- _conn.Close();
- base.Dispose();
- }
- private SqlCommand CreateCommand(string commandtext)
- {
- if (_conn == null) throw (new Exception("Not init yet."));
- SqlCommand cmd = new SqlCommand();
- cmd.Connection = _conn;
- cmd.CommandText = commandtext;
- return cmd;
- }
- public override bool SupportFS
- {
- get
- {
- return false;
- }
- }
- public override string GetFSPath(Guid guid)
- {
- throw (new NotSupportedException());
- }
- public override void Maintain()
- {
- SqlCommand cmd = CreateCommand("DELETE [AjaxUploaderTempFiles] WHERE FileTime<@Time");
- cmd.Parameters.Add("@Time", SqlDbType.DateTime).Value = DateTime.Now.AddHours(-1);
- cmd.ExecuteNonQuery();
- }
- public override bool GetInfo(Guid guid, out string filename, out int filesize, out bool persist)
- {
- SqlCommand cmd = CreateCommand("SELECT [FileName],[FileSize],[IsPersist] FROM [AjaxUploaderTempFiles] WHERE FileGuid=@Guid");
- cmd.Parameters.Add("@Guid", SqlDbType.UniqueIdentifier).Value = guid;
- using (SqlDataReader reader = cmd.ExecuteReader())
- {
- if (reader.Read())
- {
- filename = reader.GetString(0);
- filesize = reader.GetInt32(1);
- persist = reader.GetBoolean(2);
- return true;
- }
- else
- {
- filename = null;
- filesize = 0;
- persist = false;
- return false;
- }
- }
- }
- public override void Delete(Guid guid)
- {
- SqlCommand cmd = CreateCommand("DELETE [AjaxUploaderTempFiles] WHERE FileGuid=@Guid");
- cmd.Parameters.Add("@Guid", SqlDbType.UniqueIdentifier).Value = guid;
- cmd.ExecuteNonQuery();
- }
- public override void Persist(Guid guid)
- {
- SqlCommand cmd = CreateCommand("UPDATE [AjaxUploaderTempFiles] SET IsPersist=1 WHERE FileGuid=@Guid");
- cmd.Parameters.Add("@Guid", SqlDbType.UniqueIdentifier).Value = guid;
- cmd.ExecuteNonQuery();
- }
- public override void UnPersist(Guid guid)
- {
- SqlCommand cmd = CreateCommand("UPDATE [AjaxUploaderTempFiles] SET IsPersist=0 WHERE FileGuid=@Guid");
- cmd.Parameters.Add("@Guid", SqlDbType.UniqueIdentifier).Value = guid;
- cmd.ExecuteNonQuery();
- }
- public override void Save(Guid guid, string filename, System.IO.Stream stream)
- {
- int stepsize = BUFFERSIZE;
- long filesize = stream.Length;
- byte[] data = new byte[Math.Min(stepsize, filesize)];
- stream.Read(data, 0, data.Length);
- SqlCommand cmd = CreateCommand("INSERT INTO [AjaxUploaderTempFiles] ([FileGuid],[FileTime],[FileName],[FileSize],[FileData],[IsPersist]) VALUES (@Guid,@Time,@Name,@Size,@Data,0)");
- cmd.Parameters.Add("@Guid", SqlDbType.UniqueIdentifier).Value = guid;
- cmd.Parameters.Add("@Time", SqlDbType.DateTime).Value = DateTime.Now;
- cmd.Parameters.Add("@Name", SqlDbType.NVarChar, 255).Value = filename;
- cmd.Parameters.Add("@Size", SqlDbType.Int).Value = filesize;
- cmd.Parameters.Add("@Data", SqlDbType.Image).Value = data;
- cmd.ExecuteNonQuery();
- if (filesize <= stepsize)
- return;
- int sentsize = stepsize;
- try
- {
- while (true)
- {
- int readsize = stream.Read(data, 0, data.Length);
- if (readsize <= 0)
- return;
- cmd = CreateCommand("DECLARE @ptrval binary(16) ; SELECT @ptrval = TEXTPTR([FileData]) FROM [AjaxUploaderTempFiles] WHERE [FileGuid]=@Guid ; UPDATETEXT [AjaxUploaderTempFiles].[FileData] @ptrval "
- + sentsize + " 0 @Data");
- cmd.Parameters.Add("@Guid", SqlDbType.UniqueIdentifier).Value = guid;
- if (readsize != data.Length)
- {
- byte[] newdata = new byte[readsize];
- Buffer.BlockCopy(data, 0, newdata, 0, readsize);
- data = newdata;
- }
- cmd.Parameters.Add("@Data", SqlDbType.Image).Value = data;
- cmd.ExecuteNonQuery();
- sentsize += readsize;
- }
- }
- catch (Exception)
- {
- Delete(guid);
- throw;
- }
- }
- public override void AppendData(Guid guid, string filename, System.IO.Stream stream)
- {
- int stepsize = BUFFERSIZE;
- long filesize = stream.Length;
- byte[] data = new byte[stepsize];
- SqlCommand cmd = CreateCommand("SELECT [FileSize] FROM [AjaxUploaderTempFiles] WHERE [FileGuid]=@Guid ; UPDATE [AjaxUploaderTempFiles] SET [FileSize]=[FileSize]+@Size WHERE [FileGuid]=@Guid");
- cmd.Parameters.Add("@Size", SqlDbType.Int).Value = filesize;
- cmd.Parameters.Add("@Guid", SqlDbType.UniqueIdentifier).Value = guid;
- int sentsize = Convert.ToInt32(cmd.ExecuteScalar());
- try
- {
- while (true)
- {
- int readsize = stream.Read(data, 0, data.Length);
- if (readsize <= 0)
- break;
- cmd = CreateCommand("DECLARE @ptrval binary(16) ; SELECT @ptrval = TEXTPTR([FileData]) FROM [AjaxUploaderTempFiles] WHERE [FileGuid]=@Guid ; UPDATETEXT [AjaxUploaderTempFiles].[FileData] @ptrval "
- + sentsize + " 0 @Data");
- cmd.Parameters.Add("@Guid", SqlDbType.UniqueIdentifier).Value = guid;
- if (readsize != data.Length)
- {
- byte[] newdata = new byte[readsize];
- Buffer.BlockCopy(data, 0, newdata, 0, readsize);
- data = newdata;
- }
- cmd.Parameters.Add("@Data", SqlDbType.Image).Value = data;
- cmd.ExecuteNonQuery();
- sentsize += readsize;
- }
- }
- catch (Exception)
- {
- Delete(guid);
- throw;
- }
- }
- public override System.IO.Stream OpenStream(Guid guid)
- {
- SqlCommand cmd = CreateCommand("SELECT DATALENGTH([FileData]) FROM [AjaxUploaderTempFiles] WHERE FileGuid=@Guid");
- cmd.Parameters.Add("@Guid", SqlDbType.UniqueIdentifier).Value = guid;
- object val = cmd.ExecuteScalar();
- if (val == null || Convert.IsDBNull(val))
- throw (new Exception("File not found."));
- int filesize = Convert.ToInt32(val);
- int stepsize = BUFFERSIZE;
- if (filesize <= stepsize)
- {
- cmd = CreateCommand("SELECT [FileData] FROM [AjaxUploaderTempFiles] WHERE FileGuid=@Guid");
- cmd.Parameters.Add("@Guid", SqlDbType.UniqueIdentifier).Value = guid;
- using (SqlDataReader reader = cmd.ExecuteReader())
- {
- if (reader.Read())
- {
- byte[] data = (byte[])reader.GetValue(0);
- return new System.IO.MemoryStream(data);
- }
- }
- throw (new Exception("File not found."));
- }
- ReadStream readstream = new ReadStream();
- readstream.provider = this;
- readstream.guid = guid;
- readstream.filesize = filesize;
- return readstream;
- }
- class ReadStream : System.IO.Stream
- {
- public UploaderSqlServerProvider provider;
- public Guid guid;
- public int filesize;
- long pos = 0;
- byte[] _tempbuff = null;
- long _tempstart = -1;
- public override long Length
- {
- get
- {
- return filesize;
- }
- }
- public override long Position
- {
- get
- {
- return pos;
- }
- set
- {
- if (value < 0) throw (new ArgumentOutOfRangeException("Position"));
- if (value >= filesize) throw (new ArgumentOutOfRangeException("Position"));
- pos = value;
- _tempbuff = null;
- _tempstart = -1;
- }
- }
- public override int Read(byte[] buffer, int offset, int count)
- {
- int readsize = 0;
- while (true)
- {
- if (_tempstart != -1 && _tempbuff != null)
- {
- int start = (int)(pos - _tempstart);
- if (start >= 0 && start < _tempbuff.Length)
- {
- int copysize = Math.Min(count, _tempbuff.Length - start);
- Buffer.BlockCopy(_tempbuff, start, buffer, offset, copysize);
- pos += copysize;
- readsize += copysize;
- offset += copysize;
- count -= copysize;
- if (count <= 0)
- return readsize;
- }
- }
- if (pos >= filesize)
- return readsize;
- using (SqlCommand cmd = provider.CreateCommand("DECLARE @ptrval binary(16) ; SELECT @ptrval = TEXTPTR([FileData]) FROM [AjaxUploaderTempFiles] WHERE [FileGuid]=@Guid ; READTEXT [AjaxUploaderTempFiles].[FileData] @ptrval "
- + pos + " " + Math.Min(BUFFERSIZE, filesize - pos)))
- {
- cmd.Parameters.Add("@Guid", SqlDbType.UniqueIdentifier).Value = guid;
- _tempbuff = (byte[])cmd.ExecuteScalar();
- _tempstart = pos;
- }
- }
-
- }
- public override bool CanRead
- {
- get
- {
- return true;
- }
- }
- public override bool CanWrite
- {
- get
- {
- return false;
- }
- }
- public override bool CanSeek
- {
- get
- {
- return true;
- }
- }
- public override void Close()
- {
- }
- public override void Flush()
- {
- }
- public override long Seek(long offset, System.IO.SeekOrigin origin)
- {
- long oldpos = pos;
- if (origin == System.IO.SeekOrigin.Begin)
- {
- Position = offset;
- }
- if (origin == System.IO.SeekOrigin.Current)
- {
- Position += offset;
- }
- if (origin == System.IO.SeekOrigin.End)
- {
- Position = filesize + offset;
- }
- return oldpos;
- }
- public override void SetLength(long value)
- {
- throw (new NotSupportedException());
- }
- public override void Write(byte[] buffer, int offset, int count)
- {
- throw (new NotSupportedException());
- }
- }
- }
- }
- 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
- <?xml version="1.0"?>
- <configuration>
- <appSettings>
-
- <add key="RTE.ImageEditor.TempFolder" value="~/rtetemp"/>
-
- <add key="UploaderDatabase" value="server=(local);database=rtedb;uid=test;pwd=test"/>
- <add key="RTE.AjaxUploader.Provider" value="UploaderDatabaseProvider.UploaderSqlServerProvider,App_Code"/>
-
- </appSettings>
- <connectionStrings/>
- <system.web>
- <customErrors mode="Off" />
- <pages validateRequest="true" enableViewStateMac="true" enableEventValidation="false" viewStateEncryptionMode="Always" />
- <compilation debug="true">
- <assemblies>
- <add assembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/></assemblies></compilation>
- <authentication mode="None"/>
- <httpModules>
- <add name="UploadModule" type="RTE.UploadModule,RichTextEditor"/>
- </httpModules>
- </system.web>
- </configuration>
Regards, Terry
|
|
-
10-05-2012, 7:36 AM |
-
frJericho
-
-
-
Joined on 05-02-2010
-
-
Posts 169
-
-
|
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: - myHtmlEditor.Setting["InsertTemplate-CuteEditorFileStorageType"] = typeof(MyTemplateFileStorage).AssemblyQualifiedName;
- myHtmlEditor.Setting["InsertImage-CuteEditorFileStorageType"] = typeof(MyBlobFileStorage).AssemblyQualifiedName;
As you can see I have "MyTemplateFileStorage" and "MyBlobFileStorage".
|
|
-
10-05-2012, 9:54 PM |
-
cutechat
-
-
-
Joined on 07-22-2004
-
-
Posts 2,332
-
-
|
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
|
|
|
|
|