How to program to upload / send an image to an image hosting site without a browser?
I want to write a simple utility to upload images to various free image hosting sites like TinyPic or Imageshack using the context menu of the context menu for the file.
How can I do this using .NET? I have seen some linux scripts that use cURL to host images on this website, but I'm not sure how to create a post request with an image in C #?
Can anyone point me in the right direction?
EDIT:
I found a pretty good resource. Cropper, a free screenshot tool written in .net, has many open source plugins. One of them is SendToTinyPic .. complete with source. Link here:
http://www.codeplex.com/cropperplugins
The FlickrNet API makes it extremely easy to work with Flickr from within .NET. You must have a Flickr account and an API key and shared secret . Once you have what you need, working with the API is very simple:
// http://www.flickr.com/services/api/misc.api_keys.html
string flickrApiKey = "<api key>";
string flickrApiSharedSecret = "<shared secret>";
string flickrAuthenticationToken = "<authentication token>";
Flickr flickr = new Flickr( flickrApiKey, flickrApiSharedSecret );
flickr.AuthToken = flickrAuthenticationToken;
foreach ( FileInfo image in new FileInfo[] {
new FileInfo( @"C:\image1.jpg" ),
new FileInfo( @"C:\image2.jpg" ) } )
{
string photoId = flickr.UploadPicture(
image.FullName, image.Name, image.Name, "tag1, tag2" );
}
source to share
Use HttpWebRequest.
Using this class, you can send POST data to remote HTTP address, just set mime / type to multi-part / form encoding and send binary data from image with request.
http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest(VS.71).aspx
source to share
TinyPic.com does not have an API as far as I know, but the Cropper SendToTinyPic plugin is trying to load with Screen Scraper. "The official version of the plugin is not working right now, but I put together a patch using the same approach and submitted it to the cropperplugins project . This is just one original module that changed, anyone can download the plugins project and then go to my patch and it should work.
Using the patch PritScrn or Alt-PrntScrn will save the image and load into TinyPic and add the URL of the raw image to the clipboard. Everything in 2 seconds. easy.
If you don't need a real tool, you can still look at the source code of my patch to see how to POST a page with form data and upload a file. There is no direct link. See http://cropperplugins.codeplex.com/SourceControl/PatchList.aspx and look for # 3239.
This sample image was created and then automatically uploaded to tinypic.com using the Alt-PrtScrn keyboard shortcut. Sample image http://i42.tinypic.com/2dcg3ec.jpg
To enable it here, I just needed ctrl-V because the url is stored in the clipboard.
source to share