1

I want to upload an Image i selected with the PhotoChooserTask. The Selection itself works fine and i can open the Image. I also already decoded it to Base64 (Works).

Since I can't find any working example on how to work with httpwebrequest on windowsphone I tried it the following way.

    private void photoChooserTask_Completed(object sender, PhotoResult e)
    {
        if (e.TaskResult == TaskResult.OK)
        {

            //Code to display the photo on the page in an image control named myImage.
            System.Windows.Media.Imaging.BitmapImage bmp = new System.Windows.Media.Imaging.BitmapImage();
            bmp.SetSource(e.ChosenPhoto);
            MyImage.Source = bmp;

            String str = BitmapToByte(MyImage);

            String url = "http://klopper.puppis.uberspace.de/php/app/image.php?image="+ str;

            LoadSiteContent(url);

        }


    }

The rest of the code is working fine.

I get: System.IO.FileNotFoundException

If I change the str to "test" it's working.

Is the problem, that the string is too long?

4

1 回答 1

0
 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");
    }

在 windows phone 7 应用程序中引用 发布图像文件

于 2013-11-05T13:06:49.273 回答