我正在尝试使用this code
在youtube上传视频我已经通过
更改了var filePath = @"REPLACE_ME.mp4";
if (FileUpload1.HasFile)
{
var filePath = FileUpload1.FileName; // Replace with path to actual movie file.
using (var fileStream = new FileStream(filePath, FileMode.Open))
{
var videosInsertRequest = youtubeService.Videos.Insert(video, "snippet,status", fileStream, "video/*");
videosInsertRequest.ProgressChanged += videosInsertRequest_ProgressChanged;
videosInsertRequest.ResponseReceived += videosInsertRequest_ResponseReceived;
await videosInsertRequest.UploadAsync();
}
}
但是我收到一条错误信息,说这是错误的路径
我该如何解决? 另一个我尝试过:
var filePath = FileUpload1.PostedFile.FileName;
var filePath = FileUpload1.PostedFile.ToString();
var filePath = Path.GetFileName(FileUpload1.FileName);
但结果相同..
答案 0 :(得分:2)
您可能需要先使用以下方式保存文件:
var newFile = Server.MapPath(FileUpload1.FileName);
FileUpload1.SaveAs(newFile);
或者当你使用FileStream类时,你总是可以尝试:
FileUpload1.FileContent; // gets the file as a stream
答案 1 :(得分:1)
我认为你这样做了:
Server.MapPath(FileUpload1.FileName);
编辑:
或者只是使用像这样的流,如果你不一定要保存文件localy:
youtubeService.Videos.Insert(video, "snippet,status", FileUpload1.FileContent, "video/*");