1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / physical upload of files in Images and documents

physical upload of files in Images and documents

53 posts, 0 answered
  1. Frank
    Frank avatar
    19 posts
    Registered:
    03 Apr 2009
    27 Jul 2009
    Link to this post
    Anybody knows why my way isn't working?

    I guess it's not working because I use CONTENTMANAGER.EXECUTING and you use LIBRARYMANAGER.EXECUTING. What is the difference between those two?!?!

    I don't see why this must be that difficult. F.e. I only want to upload images info an custom-made foldertype. Lets say GALERYIMAGES and I want them to be scaled while uploading. And the uploading must be done on file-level and NOT into the database.

    - Problem 1: No scalling is done?!!?
    - Problem 2: Uploading an zip with more than 25 images will result in only uploading the first 25 images

    As you can see, in the previous posts. The most is handled so far so good, but this problems do still exist. Can somebody help and find out why it's not working and give me an complete sollution?
  2. Jochem Bökkers
    Jochem Bökkers avatar
    787 posts
    Registered:
    13 Aug 2007
    05 Aug 2009
    Link to this post
    Frank was so kind enough to hand over this project to me and I'd like to continue this thread. First of all since I don't know what's all gonna change in SP3 and ver 4.0 we're (for now) sticking to a quick and dirty solution.

    With version 3.6SP2 We're able to store images/documents to on a file level. Deleting and updating also functions and we're ignoring scaling etc until the next release (According to Parvan this will be changed in in next release).

    After uploading a ridiculous large image I noticed that the table  dbo.sf_VrsBinData is still getting filled.
    (We're testing/building this on community edition until we're ready for production with standard edition)

    Any suggestions? or are we still doomed for rewriting the provider?
  3. Jochem Bökkers
    Jochem Bökkers avatar
    787 posts
    Registered:
    13 Aug 2007
    05 Aug 2009
    Link to this post
    Also with the same code when we're storing images on file, they're stored according to this:

    string storePath = HttpContext.Current.Server.MapPath("~/Files/" + provider.Name + "/" + libraryItem.GetMetaData("Name") + file_extension);  
     
     

    libraryItem.GetMetaData("Name") gives us the name of the image, but does anyone know how we insert the library name in the path so it will become something like "~/Files/Libraries/LibraryName/NameofImage.ext" ?

    Thanks,
    Jochem Bökkers
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    06 Aug 2009
    Link to this post
    Hello Jochem,

    You can use GetLibrary method to add the library name.  Then add it to the string.

    Sample code:

    Telerik.Libraries.ILibrary theLibrary = libraryManager.GetLibrary("My First Library"); 

    You can use the following method to get all items form a given library.

    The GetImages(int from, int max, string sortExp, Guid[] parentIDs) 

    parentIDs array has a library ID and will return the files for the specified library only.


    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  5. Gabe Sumner
    Gabe Sumner avatar
    440 posts
    Registered:
    09 Sep 2007
    24 Aug 2009
    Link to this post

    Slow reply on this.  I was intrigued by the path Dido suggested above.  I was also emailing privately with Jochem and decided to pursue the Custom Library Provider path.  If done correctly this provider would replace the existing LibraryProvider and store files outside the database.  Once in place, no other changes would need made.

    I'll keep working on this LibraryProvider and probably turn this into a blog post.  However, below is a work in progress.

    Create the following file: ~/App_Code/LibraryProvider.cs

    using System;  
    using System.Web;  
    using System.IO;  
    using Telerik.Cms.Engine;  
    using Telerik.Cms.Engine.Data;  
     
    namespace SitefinityWatch  
    {  
        public class LibraryProvider : Telerik.Libraries.Data.DefaultProvider  
        {  
            private const string fileExtension = "dat";  
            private const string filePath = "~/Images";  
     
            private CmsContentBase SetContentBase(IContent content)  
            {  
                IContent content2 = this.GetContent(content.ID);  
                if (content2 == null)  
                {  
                    content2 = this.CreateContent(content.MimeType);  
                }  
                content2.Content = content.Content;  
                foreach (string str in this.MetaKeys.Keys)  
                {  
                    content2.SetMetaData(str, content.GetMetaData(str));  
                }  
                return (CmsContentBase)content2;  
            }  
     
            private string GetFilePath(Guid id)  
            {  
                return HttpContext.Current.Server.MapPath(filePath + "/" + id + "." + fileExtension);  
            }  
     
            public override void SaveContent(IContent content, bool fireEvents)  
            {  
                CmsContentBase contentBase = null;  
                if (content is CmsContentBase)  
                {  
                    contentBase = (CmsContentBase)content;  
                }  
                else 
                {  
                    contentBase = this.SetContentBase(content);  
                }  
     
                File.WriteAllBytes(GetFilePath(contentBase.ID), contentBase.Content as byte[]);  
                contentBase.Content = new byte[0];  
                base.SaveContent(contentBase as IContent, fireEvents);  
            }  
     
            private IContent GetContent(IContent content)  
            {  
                try 
                {  
                    if (File.Exists(GetFilePath(content.ID)) == true)  
                    {  
                        content.Content = File.ReadAllBytes(GetFilePath(content.ID));  
                    }  
                }  
                catch 
                {  
     
                }  
                return content as IContent;  
            }  
     
            public override IContent GetContent(Guid id)  
            {  
                CmsContentBase content = base.GetContent(id) as CmsContentBase;  
                return GetContent(content);  
            }  
     
            public override IContent GetContent(string url)  
            {  
                CmsContentBase content = base.GetContent(url) as CmsContentBase;  
                return GetContent(content);  
            }  
        }  

    Find the following section in the ~/web.config and replace Sitefinity's LibraryProvider with this custom LibraryProvider.

    <cmsEngine defaultProvider="Generic_Content">  
      <providers> 
        <add name="Libraries" urlRewriteFormat="~/{Provider}/{LibraryName}/[Name].sflb.ashx" urlDateTimeFormat="yy-MM-dd" urlWhitespaceChar="_" visible="False" defaultMetaField="Name" applicationName="/Libraries" allowVersioning="False" allowLocalization="False" localizationProviderName="" allowWorkflow="False" securityProviderName="" versioningProviderName="" connectionStringName="GenericContentConnection" type="SitefinityWatch.LibraryProvider, App_Code" tagEditorTemplate="~/Sitefinity/Admin/ControlTemplates/Libraries/BatchTagsEditor.ascx" /> 
      </providers> 
    </cmsEngine> 

    Thumbnails and versioning are not yet handled.  I have not done extensive testing on this, but it will store the file outside the database.  It might help others who are pursuing this path.

    Gabe Sumner
    http://www.sitefinitywatch.com/

  6. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    27 Aug 2009
    Link to this post
    Hi,

    This provider will be awesome when it reaches the completed stage. We will help with the testing! :)

    Kind regards,
    Georgi
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  7. Nauman
    Nauman avatar
    35 posts
    Registered:
    28 Jul 2008
    24 Feb 2010
    Link to this post
    Hi Gabe

    Can you please inform, have you make any modification in the LibraryProvider, or did you make any blog post, please update the thread.

    Thanks
    Nauman Ahmed
  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    24 Feb 2010
    Link to this post
    Hello Nauman,

    The solution is not so simple although we provided lot of code here. There will be a SP in the middle of March where we are going to implement this functionality only for documents.

    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  9. Nauman
    Nauman avatar
    35 posts
    Registered:
    28 Jul 2008
    24 Feb 2010
    Link to this post
    after a long wait, finally sitefinity is there, so started count down...

    cheers
    nauman ahmed
  10. Logisz
    Logisz avatar
    8 posts
    Registered:
    17 Mar 2009
    24 Feb 2010
    Link to this post
    Why only for documents?

    For images the same problem still exists.
  11. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    24 Feb 2010
    Link to this post
    Hi Frank,

    This will be a new DataProvider for the Images and Documents module, it will be able to store all types of library items on a physical location rather than db. So images are in this case too.

    Sincerely yours,
    Radoslav Georgiev
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  12. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    24 Feb 2010
    Link to this post
    Hello Frank,

    Update: I am sorry for the misleading information. The initial implementations if for documents, however we have plans to extend it to all content items. So most probably the images will also make it in the provider. If however this does not happen we will provide tips on how to achieve this.

    Best wishes,
    Radoslav Georgiev
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  13. Logisz
    Logisz avatar
    8 posts
    Registered:
    17 Mar 2009
    24 Feb 2010
    Link to this post
    In this case, about what version are we talking??
    - v3.6
    - v3.6SP2
    -v3.7

    And wil all this problems and issues above be solved in v4.0?
  14. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    24 Feb 2010
    Link to this post
    Hi Frank,

    The provider will be implemented for Sitefinity 3.7 SP3 as written in one of the previous posts

    "There will be a SP in the middle of March where we are going to implement this functionality only for documents."

    At this stage there is not files provider which is not an issue. This is a missing implementation. We are going to have files provider with Sitefinity 4.0 as well.

    Regards,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  15. Jochem Bökkers
    Jochem Bökkers avatar
    787 posts
    Registered:
    13 Aug 2007
    24 Feb 2010
    Link to this post
    Great news!

    We'll await next month and see where we are then. We're really anxious to get started.

    J.
  16. J.R. Garcia
    J.R. Garcia avatar
    24 posts
    Registered:
    12 Aug 2008
    24 Feb 2010
    Link to this post
    Is there any way to accomplish this on Sitefinity 3.5 using a custom provider? I don't want to use the global.asax hack that is talked about throughout the post. Did anything come of Gabe's custom provider? Has it been thoroughly tested?

    Thanks,
    J.R. Garcia
  17. Gabe Sumner
    Gabe Sumner avatar
    440 posts
    Registered:
    09 Sep 2007
    25 Feb 2010
    Link to this post
    Hey JR,

    I just pulled up my old project to refresh my memory.

    I worked on this off & on for weeks before finally moving onto other projects.  As I recall the code above fetches files from the file system but does not actually prevent the files from being stored in the database.  Which defeats the purpose of this code...

    My original idea was to override a few methods in "Telerik.Libraries.Data.DefaultProvider".  However, after a lot of hacking, I realized that this class is primarily just passing off work to "Telerik.Cms.Engine.Data.Providers.DefaultProvider".  Consequently, overriding these methods doesn't change a lot of the Library Provider's behavior.

    To fix this, I inherited from the "Providers.DefaultProvider" class instead of the "Libraries.DefaultProvider" and attempted to override a few of those methods.  This created a lot of problems and I was eventually informed that this would not work.  My only alternative would be to create my own persistance class from scratch.  This would be a sizable job and strays pretty far from core Sitefinity functionality.

    I'm okay with tweaking the system, but I don't feel comfortable telling customers to completely re-write core providers.  Regardless of whether it works or not, these customizations probably won't survive an upgrade.  At this point I abandoned this project.

    Sorry for the bad news.  I really did try on this, but I couldn't come up with an elegant looking solution.

    However, if I'm reading Ivan's previous post correctly there is a partial solution coming with SP3 in a few weeks.  

    Gabe Sumner
    Evangelist
    Telerik | Sitefinity CMS
  18. J.R. Garcia
    J.R. Garcia avatar
    24 posts
    Registered:
    12 Aug 2008
    07 Jun 2010
    Link to this post
    I was wondering if there was any more progress on doing this. We have a client that is unable to use the database to store their files. They have several GBs of audio and video that we don't have room for in the database. If this isn't available in Sitefinity yet, are there any workarounds?

    Thanks,
    J.R. Garcia
  19. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    08 Jun 2010
    Link to this post
    Hello J.R. Garcia,

    Yes, since 3.7 SP3 we implemented Files provider How to enable files provider in Sitefintiy 3.7

    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  20. wsstark
    wsstark avatar
    4 posts
    Registered:
    14 May 2010
    08 Jun 2010
    Link to this post
    Ivan or Gabe,

      Has anyone looked into keeping the save to db function and implementing Filestream on their SQL Server 2008?  From what I have read this will maintain the speed of the db while storing the files in the file system.  I am thinking about this for my own site and would like to know your thoughts.

    Regards,
      Scott
  21. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    08 Jun 2010
    Link to this post
    Hi wsstark,

    The Files provider saves only the content to the File system. The metadata is saved into the database. Uploading large files to the database is dependent process and there are plans to provide uploading large files to the database in Sitefinity 4.0. Generally the problem is that the data should be uploaded on chunks which will not overload the SQL server.

    All the best,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  22. J.R. Garcia
    J.R. Garcia avatar
    24 posts
    Registered:
    12 Aug 2008
    14 Jun 2010
    Link to this post
    Is there a way to move all files already stored in the database to the file system? We have about 4-5 GBs of data that we'd want to get out of the database.

    Thanks,

    J.R. Garcia
  23. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    15 Jun 2010
    Link to this post
    Hi J.R. Garcia,

    You can take a look at this forum post. The last thread reply contains a project with code which does this.

    Kind regards,
    Radoslav Georgiev
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Register for webinar
53 posts, 0 answered
1 2