Quantcast ImageShack and Shell programing Text - Physics Forums Library

PDA

View Full Version : ImageShack and Shell programing


rootX
Aug7-08, 10:38 PM
I am creating a product (for personal use)
when I left click an image, "Upload to ImageShack" should show up
and when I click that I want to upload the file to image shack and provide me the uploaded file address in dialog box/other ways

Currently, I am working on .Net web application. I copied all java script from image shack and put it under my project. It is almost done (few problems)

Then, I am thinking of making an .exe file that would start this web application or it might talk to imageshack directly.
http://imageshack.us/

And, that "Upload to ImageShack" should start the .exe program.

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\*\shell\Open with Notepad]

[HKEY_CLASSES_ROOT\*\shell\Open with Notepad\command]
@="notepad.exe %1"

This opens up notepad, and I want to make similar that opens my program and provide file location as a parameter.

Any help would be appreciated!


This is my second personal project. In the first one, I created excel 2007 add-in that emails my files to gmail account when I click a button (I really wanted it for backing up my data and remote use)
If there's a better way to achieve the final functioning?

dashed
Aug13-08, 09:20 AM
ImageShack has an API:
http://reg.imageshack.us/content.php?page=developer

Using the XML API provided should be easy to integrate.

Refer to php code: http://elliottback.com/wp/archives/2008/06/01/using-the-imageshack-xml-api/

The code provided, should be fairly easy to modify and convert to .NET code.

Imageshack some simple examples to using their API once you have requested for a developer key. But these are geared towards web based applications.

rootX
Aug13-08, 09:40 PM
ImageShack has an API:
http://reg.imageshack.us/content.php?page=developer

Using the XML API provided should be easy to integrate.

Refer to php code: http://elliottback.com/wp/archives/2008/06/01/using-the-imageshack-xml-api/

The code provided, should be fairly easy to modify and convert to .NET code.

Imageshack some simple examples to using their API once you have requested for a developer key. But these are geared towards web based applications.

Thanks that was neat!

using HttpRequest class, it's simple 20 lines code but mine didn't work. Doesn't return anything
One question: I passed file name first and then file stream .. none worked :cry:

they say

Send the following variables via POST to http://www.imageshack.us/index.php

fileupload; (the image)
xml = "yes"; (specifies the return of XML)
cookie; (registration code, optional)
Assuming the upload completes without problems, the xml data may be manipulated as necessary. To show the user the results of his or her upload, redirect the user to <done_page>, as defined in the XML feedback agent.

my code:

string fileName = "C:\\Documents and Settings\\Harmeet Cheema\\My Documents\\My Pictures\\Avril.JPG";

StreamReader streamRdr = new StreamReader(fileName);
String file = streamRdr.ReadToEnd();
byte[] buffer = Encoding.Unicode.GetBytes("fileupload=" + file + "&xml=yes");
//Initialisation, we use localhost, change if appliable
HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create("http://www.imageshack.us/index.php");
//Our method is post, otherwise the buffer (postvars) would be useless
WebReq.Method = "POST";
//We use form contentType, for the postvars.
WebReq.ContentType = "application/x-www-form-urlencoded";
//The length of the buffer (postvars) is used as contentlength.
WebReq.ContentLength = buffer.Length;
//We open a stream for writing the postvars
Stream PostData = WebReq.GetRequestStream();
//Now we write, and afterwards, we close. Closing is always important!
PostData.Write(buffer, 0, buffer.Length);
PostData.Close();
//Get the response handle, we have no true response yet!
HttpWebResponse WebResp = (HttpWebResponse)WebReq.GetResponse();
//Let's show some information about the response
Console.WriteLine(WebResp.StatusCode);
Console.WriteLine(WebResp.Server);

rootX
Aug13-08, 09:44 PM
But, using dirty solution. Make direct post to their page, I managed to get the file address..

Now,
I have a .EXE console application that would return the photo uploaded http address when you pass the file address to it from args.

So, I am left it putting it together with context menu

dashed
Aug13-08, 10:46 PM
I recommend using the curl library when communicating with a web service. I don't know if .NET has native functions for this.

http://curl.haxx.se/libcurl/dotnet/

Their PHP example: http://reg.imageshack.us/xmlapi.zip

function uploadToImageshack($filename) {

//Connect to imageshack
$ch = curl_init("http://www.imageshack.us/index.php");

//$_POST data
$post['xml']='yes';
$post['fileupload']='@'.$filename;

//curl stuff
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 240);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect: '));

$result = curl_exec($ch);
curl_close($ch);

if (strpos($result, '<'.'?xml version="1.0" encoding="iso-8859-1"?>') === false) {
return 'failed';
} else {
return $result; // XML data
}
}

Try to convert this function into .NET code. The parameter $filename is the image store temporarily on disk to be uploaded to imageshack.

The xml data should be within the variable $result.

Use a xml parser to get the information you need.

You may use a .NET xml parser (I dont know if .NET provides this function natively):
http://www.chilkatsoft.com/dotNetXml.asp


I hope this helps.

rootX
Aug13-08, 10:53 PM
I recommend using the curl library when communicating with a web service. I don't know if .NET has native functions for this.

http://curl.haxx.se/libcurl/dotnet/

Their PHP example: http://reg.imageshack.us/xmlapi.zip

function uploadToImageshack($filename) {

//Connect to imageshack
$ch = curl_init("http://www.imageshack.us/index.php");

//$_POST data
$post['xml']='yes';
$post['fileupload']='@'.$filename;

//curl stuff
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 240);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect: '));

$result = curl_exec($ch);
curl_close($ch);

if (strpos($result, '<'.'?xml version="1.0" encoding="iso-8859-1"?>') === false) {
return 'failed';
} else {
return $result; // XML data
}
}

Try to convert this function into .NET code. The parameter $filename is the image store temporarily on disk to be uploaded to imageshack.

The xml data should be within the variable $result.

Use a xml parser to get the information you need.

You may use a .NET xml parser (I dont know if .NET provides this function natively):
http://www.chilkatsoft.com/dotNetXml.asp


I hope this helps.

Thanks, I will look further into that way.

Currently, I have one working solution, so I just want to get done the whole thing working before I start making it cleaner.

Context menu click --> open .exe and provide file location as args paramter...

kenewbie
Aug14-08, 04:38 AM
Instead of a custom entry in the context menu, you can consider using "send to".

Simply make your imageshack.exe take a filename as the first parameter, then put imageshack.exe in the "documents and settings\name\send to\" folder.

Then you can right-click any file, go to "send to" and choose imageshack.

k

rootX
Aug14-08, 06:18 AM
Instead of a custom entry in the context menu, you can consider using "send to".

Simply make your imageshack.exe take a filename as the first parameter, then put imageshack.exe in the "documents and settings\name\send to\" folder.

Then you can right-click any file, go to "send to" and choose imageshack.

k

Thanks that was easy! Finished in 5 seconds :). I couldn't find send to in C:\doc .. so I ran "sendto" from run.

Now, I have simple application that uploads the file, returns in console and works perfectly!
Need to work on making it more user friendly .. and cleaner

I will upload my code shortly. It would be less than 100 lines (now it's about 200 ..)

rootX
Aug14-08, 04:26 PM
Thanks guys!
I am done :biggrin:

http://img237.imageshack.us/img237/2569/screen1rc1.png
Select the file
http://img519.imageshack.us/img519/7682/screen2uv9.png
Click on the upload button
http://img237.imageshack.us/img237/8623/screen3tp1.png
It anagrammatically copies to the clipboard!

rootX
Aug14-08, 05:51 PM
Thanks guys!
I am done :biggrin:

http://img237.imageshack.us/img237/2569/screen1rc1.png
Select the file
http://img519.imageshack.us/img519/7682/screen2uv9.png
Click on the upload button
http://img237.imageshack.us/img237/8623/screen3tp1.png
It anagrammatically copies to the clipboard!

And, it's possible to upload multiple files and all images in a directory.

peismgh
Nov29-08, 04:13 PM
Hi,

I've been looking for a program which does this - any link to the download anywhere?

Thanks.