我正在处理一个sharepoint项目,在该项目中,我必须将文档库中的视频作为视频集上传。创建视频集后,我必须上传视频,并从视频中获取缩略图并上传。视频上传成功使用
spfile = item.Folder.Files.Add(fuUpload.FileName, fuUpload.PostedFile.InputStream, true);我正在使用Nreco从视频中获取缩略图。然而,我的代码在本地机器上运行良好,但当我在其他pc浏览器上使用我的应用程序时,它给出了错误"http://mysite/Download/abc/abc.mp4:Server returned 401 Unauthorized (authorization failed) (退出代码: 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;
}发布于 2016-02-08 14:47:23
最后,我设法解决了这个问题。由于某些原因,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;
}有人可能会从我的回答中节省一些时间。如果有人有更好的解决方案,请让我知道。
https://stackoverflow.com/questions/34943201
复制相似问题