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

Forums / Developing with Sitefinity / Saving Video to Library in WS does not generate Thumbs

Saving Video to Library in WS does not generate Thumbs

2 posts, 0 answered
  1. Trever Archibald
    Trever Archibald avatar
    2 posts
    Registered:
    01 Dec 2009
    11 Dec 2009
    Link to this post

    Hello, we have a custom LibraryItemUpload module that calls a web service to encode video for streaming then saves to a video or custom library. The video is saving to the database just fine howerver I cannot seem to generate a thumbnail since we're bypassing the Sitefinity upload routine. I generate a thumb and save it to a directory on the web server as part of the encoding process so I need a way to either save this back to sitefinity or use the built in thumb generation either is fine. Below is the mehtod that gets called in the web service to save the encoded video back to the library. I have both the video and my generated thumb in a byte array. I upload to sitefinity, set metadata etc without a problem, Just not sure if I'm doing something wrong in the libraryManage.AddThumbnail call?. I don't see a record in the db and when viewing page source I see the thumbnail img with an empty src="" attribute.
     

     

    1   public bool WriteFileToSitefinity(byte[] encodedFile, byte[] thumbData)  
    2         {  
    3            bool saved = false;  
    4            IThumbnail thumbcontent = null;  
    5            IContent content = null;  
    6  
    7             try 
    8             {  
    9                 //save to lib. Save bytes to db                   
    10                 LibraryManager libraryManager = new Telerik.Libraries.LibraryManager("Libraries");                  
    11                 ILibrary library = libraryManager.GetLibrary(_libraryName);                   
    12                 Telerik.Cms.Engine.IContent newContent = libraryManager.CreateContent("video/x-ms-wmv");  
    13                 newContent.ParentID = library.ID;  
    14                    
    15                 // upload the file  
    16                 try 
    17                 {  
    18                     content = libraryManager.UploadFile  
    19                         (  
    20                          encodedFile,_fileName,".wmv""video/x-ms-wmv", encodedFile.LongLength, library  
    21                         );    
    22    
    23                 }  
    24                 catch (ArgumentException ex)  
    25                 {  
    26                     throw new Exception("An Invalid Argument error occured saving file to Sitefinity Library.", ex.InnerException);  
    27                 }  
    28  
    29                 //Add a thumbnail  
    30                 try 
    31                 {  
    32  
    33                     thumbcontent = libraryManager.AddThumbnail  
    34                         (  
    35                          content, thumbData, "image/jpeg"".jpg", _videoThumb.Replace(".jpg"""), true 
    36                         );  
    37  
    38                 }  
    39                 catch (ArgumentException ex)  
    40                 {  
    41                     throw new Exception("An Invalid Argument error occured saving Thumbnail to Sitefinity Library.", ex.InnerException);  
    42                 }  
    43  
    44  
    45                 // save the image as a content of the file  
    46                 //Set Properties  
    47                 StagedContent temp = libraryManager.GetCurrentState(content.ID) as StagedContent;  
    48                 temp.Owner = _author;  
    49                 temp.SetMetaData("Author", _author);  
    50                 temp.SetMetaData("Description", _description);  
    51                 libraryManager.SaveContent(temp, ContentStatus.Published);     
    52                 newContent.Content = content;                
    53                 //after save success.  
    54                 saved = true;  
    55             }  
    56             catch (Exception ex)  
    57             {  
    58                 throw new Exception("Unexpected error occured saving file to Sitefinity Library.", ex.InnerException);  
    59             }  
    60       
    61            return saved;  
    62           
    63         }  
    64  

     

     

  2. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    11 Dec 2009
    Link to this post
    Hi Trever Archibald,

    Thank you for using our services.

    Since you have the bellow codein your WS method, which actually generates a thumbnail object:
    //Add a thumbnail 
    try
        thumbcontent = libraryManager.AddThumbnail 
            
             content, thumbData, "image/jpeg", ".jpg", _videoThumb.Replace(".jpg", ""), true
            ); 
     
    }

    You do not add this object to the thumbnails collection of your newly created content item. Can you try this:
    //Set Properties 
    StagedContent temp = libraryManager.GetCurrentState(content.ID) as StagedContent; 
    temp.Owner = _author;
    temp.Thumbnails.Add(thumbcontent);


    Sincerely yours,
    Radoslav Georgiev
    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.
2 posts, 0 answered