简体   繁体   English

任何人都有WP8中Webclient上传的示例示例?

[英]Anyone have example sample for Webclient upload in WP8?

I found many tutorials using WebClient to upload files. 我发现许多使用WebClient上传文件的教程。 by using webCleint.uploadFile. 通过使用webCleint.uploadFile。

But in WP8 there is no support. 但在WP8中没有任何支持。 Anyone have any idea??? 任何人都有任何想法???

Check this article: http://chriskoenig.net/2011/08/19/upload-files-from-windows-phone/ 查看这篇文章: http//chriskoenig.net/2011/08/19/upload-files-from-windows-phone/

private void task_Completed(object sender, PhotoResult e)
        {
            if (e.TaskResult != TaskResult.OK)
                return;

            const int BLOCK_SIZE = 4096;

            Uri uri = new Uri("http://localhost:4223/File/Upload", UriKind.Absolute);

            WebClient wc = new WebClient();
            wc.AllowReadStreamBuffering = true;
            wc.AllowWriteStreamBuffering = true;

            // what to do when write stream is open
            wc.OpenWriteCompleted += (s, args) =>
            {
                using (BinaryReader br = new BinaryReader(e.ChosenPhoto))
                {
                    using (BinaryWriter bw = new BinaryWriter(args.Result))
                    {
                        long bCount = 0;
                        long fileSize = e.ChosenPhoto.Length;
                        byte[] bytes = new byte[BLOCK_SIZE];
                        do
                        {
                            bytes = br.ReadBytes(BLOCK_SIZE);
                            bCount += bytes.Length;
                            bw.Write(bytes);
                        } while (bCount < fileSize);
                    }
                }
            };

            // what to do when writing is complete
            wc.WriteStreamClosed += (s, args) =>
            {
                MessageBox.Show("Send Complete");
            };

            // Write to the WebClient
            wc.OpenWriteAsync(uri, "POST");
        }

And this two: Upload image using ASP.NET WebAPI using a model http://blog.anthonybaker.me/2013/06/how-to-upload-file-from-windows-phone.html 这两个: 使用ASP.NET WebAPI使用模型上传图像 http://blog.anthonybaker.me/2013/06/how-to-upload-file-from-windows-phone.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM