Image Upload using a stream

Topics: User Forum
Nov 12, 2006 at 11:37 AM
hi

i have successfully authenticated using flickrnet and now i want to upload a picture directly from the clipboard. therefore i wrote the image data to a memorystream encoded in png.

System.IO.MemoryStream stream = new System.IO.MemoryStream();
ImageData.Save(stream, ImageFormat.Png);

i can see that there are a around 150k of data in the stram after this, which fits a full screen capture. i then try to upload...

string photoId = flickr.UploadPicture(stream, title, description, "tags", uploadAsPublic, isFamily, isFriend);

...but photoid remains null and asking the stream for its length causes a streamdisposedexception.

any idea whats wrong or how to continue the bughunt?
Coordinator
Nov 12, 2006 at 8:58 PM
Streams work by moving along the length of the stream, one byte at a time basically - they do this by maintaining a pointer to the current position in the stream and then reading the next byte when asked.

After saving the image to the stream the pointer will be at the end of the stream, therefore before the FlickrNet library can read the stream you need to move this pointer back to the beginning.

e.g.: stream.Position = 0

Let me know if that works.

Sam