0

我正在尝试使用 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);
    }
}

请建议如何上传

4

1 回答 1

0

我找到了答案,我使用上面的代码只是传递了错误的 url..

于 2013-06-27T17:50:20.643 回答