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?

Frnak
  • 6,601
  • 5
  • 34
  • 67
  • The string is probably too long indeed. De facto standard seems to be 2000 characters. http://stackoverflow.com/questions/417142/what-is-the-maximum-length-of-a-url-in-different-browsers – venerik Nov 05 '13 at 12:07

1 Answers1

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

Reference to post image file in windows phone 7 application

Community
  • 1
  • 1
DotNetRussell
  • 9,716
  • 10
  • 56
  • 111
  • Thanks but how do I "catch" it on serverside using php? Can you give me an example code? – Frnak Nov 05 '13 at 22:12
  • Code isn t working for me, task ends with blackscreen, nothing happens. – Frnak Nov 05 '13 at 22:30
  • @FrankProvost in regards to your php question that is a seperate question and needs to be posted as such. As far as this code goes, it is proven to work code. If you are still having underlying issues repost it in a separate question or provide more details here. – DotNetRussell Nov 06 '13 at 12:45
  • I finally got it working, thx - but why would it be a seperate question? Since I'm new to Stackoverflow I would think, that the titel of my post is also including the php code. Anyway I got it working =) – Frnak Nov 06 '13 at 14:03
  • You're right, but if you want to inquire about php code you need to post that as well. People are good here, real good, but not mind readers – DotNetRussell Nov 06 '13 at 14:07
  • bytes = br.ReadBytes(BLOCK_SIZE); this line is not working the bytes are getting in array. – Muneeb Zulfiqar Mar 01 '14 at 17:31