0

I am trying to use Tweetsharp's SendTweetWithMedia with a image which I don't have stored locally, I only have a url. All the examples I have found of SendTweetWithMedia use a file on the local system.

var thumb = "http://somesite.net/imageurl";
var service = new TwitterService(key, secret);
service.AuthenticateWith(token, tokenSecret);
var req = WebRequest.Create(thumb);
using (var stream = req.GetResponse().GetResponseStream())
{
    response = service.SendTweetWithMedia(new SendTweetWithMediaOptions
    {
    Status = tweet.Trim(),
    Images = new Dictionary<string, Stream> { { fullname, stream } }
    });
} 

I get the following error from SendTweetWithMedia:

'System.NotSupportedException': This stream does not support seek operations.

I could download the file from the url and save locally, but I'd rather use the url. Is this possible?

Rob Sedgwick
  • 4,342
  • 6
  • 50
  • 87
  • 1
    You can check with reading stream and storing it to memory stream like this in accepted answer : http://stackoverflow.com/questions/3434007/error-this-stream-does-not-support-seek-operations-in-c-sharp – Akash KC Feb 01 '17 at 22:13
  • Thanks I tried using a memory stream and it did get further. However SendTweetWithMedia just times out and returns null after about 1 minute. To be honest I might as well download the url and save to a local file as convert everything to a MemoryStream. At least I'd be then on the familiar ground everyone else seems to be using. – Rob Sedgwick Feb 01 '17 at 23:12

1 Answers1

0

In the end, I just created a temporary file:

byte[] data;
using (var client = new WebClient())
{
    data = client.DownloadData(thumb);
}
File.WriteAllBytes($"{Path.GetTempPath()}\\xyz.jpg", data);

best answer I could come up with. Still a few more lines than I'd like though.

Rob Sedgwick
  • 4,342
  • 6
  • 50
  • 87