2016-01-22 53 views
0

我正在處理一個SharePoint項目,在該項目中我必須將文檔庫中的視頻作爲視頻集上傳。創建視頻集後,我必須上傳視頻並從視頻中獲取縮略圖並上傳。視頻成功上傳使用從視頻GetThumbnail的URL使用Nreco

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

我正在使用Nreco從視頻中獲取縮略圖。但是,我的代碼在本地機器上正常工作,但是當我從其他PC瀏覽器使用我的應用程序時,它給出錯誤「http://mysite/Download/abc/abc.mp4:服務器返回401未授權(授權失敗)(退出代碼:1)」。

ffMpeg.GetVideoThumbnail(videoPath,ms,10);錯誤行。

這裏是我使用

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; 
    } 
+0

您有權從其他電腦訪問縮略圖嗎? –

+0

是的,當我在瀏覽器上直接點擊url時,它播放視頻文件。 –

回答

1

最後,我已成功地解決了這個代碼。由於某些原因,SharePoint不允許我使用NReco直接從URL訪問文件,所以我調整了這樣的功能。

而不是使用文件的URL作爲參數我用它自己的文件對象。並將流複製到虛擬目錄中的服務器臨時文件夾中,然後我使用系統上的文件路徑爲NRreco創建縮略圖。並最終從服務器上刪除該文件。

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; 
     } 

有人可能會從我的答案中節省一些時間。如果有人有更好的解決方案,請讓我知道。