0

I working on a sharepoint project in which i have to upload the videos in the document library as videoset. after creating a video set i have have to upload the video and fetch the thumbnail from the video and upload it. video is uploaded succesfully using

spfile = item.Folder.Files.Add(fuUpload.FileName, fuUpload.PostedFile.InputStream, true);

I am using using Nreco to get thumbnail from the video. However my code works fine on local machine but its giving error "http://mysite/Download/abc/abc.mp4: Server returned 401 Unauthorized (authorization failed) (exit code: 1)" when i am using my application from other pc browsers.

ffMpeg.GetVideoThumbnail(videoPath, ms, 10); the error line.

here is the code i am using

private MemoryStream SaveThumbnail(string videoPath) 
    {
        MemoryStream ms; 
        try 
        {
            videoPath = "http://mysitehttp/Download/abc/abc.mp4"
            ms = new MemoryStream();
            SPSecurity.RunWithElevatedPrivileges(delegate() {

                var ffMpeg = new NReco.VideoConverter.FFMpegConverter();
                ffMpeg.GetVideoThumbnail(videoPath, ms, 10); 
            });


        }
        catch(Exception ex)
        {
            throw ex;
        }

        return ms;
    }

1 Answers1

1

Finally I have managed to solve this. For some reason SharePoint did not allow me to access the file directly from URL using NReco so i tweaked the function like this.

Instead of using file URL as argument i used the file object it self. and copied the stream on server temp folder in virtual directories then i used the file path on the system for NRreco to create the thumbnail. and in the end deleted the file from the server.

private MemoryStream SaveThumbnail(SPFile videoFile) 
        {
            MemoryStream ms; 
            try 
            {
                //Creating Temp File Path to be used by Nreco


                ms = new MemoryStream();
                SPSecurity.RunWithElevatedPrivileges(delegate() {

                    string destinationFile = Path.Combine(Path.GetTempPath(), Guid.NewGuid() + videoFile.Name);

                    //Copying the content the content of the file at temp loaction from stream
                    using (FileStream fileStream = File.Create(destinationFile))
                    {
                        Stream lStream = videoFile.OpenBinaryStream();
                        byte[] contents = new byte[lStream.Length];
                        lStream.Read(contents, 0, (int)lStream.Length);
                        lStream.Close();

                        // Use write method to write to the file specified above
                        fileStream.Write(contents, 0, contents.Length);
                        fileStream.Close();
                    }


                    var ffMpeg = new NReco.VideoConverter.FFMpegConverter();
                    ffMpeg.GetVideoThumbnail(destinationFile, ms, 10);

                    System.IO.File.Delete(destinationFile);
                });


            }
            catch(Exception ex)
            {
                throw ex;
            }

            return ms;
        }

Someone might save some time from my answer. if anyone has a better solution let me know please.