我正在尝试使用 webclient 上传视频,但我无法这样做这是我的代码
private void UploadFile(string fileName)
{
Stream data = Application.GetResourceStream(new Uri(@"DemoProject;component/test.mp4", UriKind.Relative)).Stream;
UriBuilder ub = new UriBuilder("http://www.abc.com/xyz/");
ub.Query = string.Format("name={0}", fileName);
WebClient c = new WebClient();
c.OpenWriteCompleted += (sender, e) =>
{
PushData(data, e.Result);
e.Result.Close();
data.Close();
};
c.OpenWriteAsync(ub.Uri);
}
private void PushData(Stream input, Stream output)
{
byte[] buffer = new byte[4096];
int bytesRead;
while ((bytesRead = input.Read(buffer, 0, buffer.Length)) != 0)
{
output.Write(buffer, 0, bytesRead);
}
}
请建议如何上传