Jump to content

photo upload/ imageshack api


AutID
 Share

Recommended Posts

Hello,

I was trying to create an app that will upload images on imageshack and then share them with some people.
Doing a search on the forum I found a topic that MrCreator was asking for some help.
Then 3 year later he came up with this script

#include <Array.au3>
$sFile = @ScriptDir & "large.jpg"
_UploadTo_Imageshack($sFile)
Func _UploadTo_Imageshack($sFile, $iRet_Type = 0)
    $sLocalFile = $sFile ;Local file
 $sKey = '79CLNOQVc318ccacdcd4716cae82f7f414ac3f8f'
    $sHost = 'http://imageshack.us' ;Upload page addresss
    $sFormAction = '/upload_api.php'  ;Upload form action ("form action=...upload.php)"
    $sFormName = 'fileupload' ;Upload form name ("input name=uploadfile")
    $sResponse = _TCPFileUpload($sLocalFile, $sHost, $sFormAction, $sFormName)
    Local $aRet[4] = _
        [ _
            StringRegExpReplace($sResponse, '(?is).*<(image_link)>(.*?)</\1>.*', '\2'), _
            StringRegExpReplace($sResponse, '(?is).*<(image_html)>(.*?)</\1>.*', '\2'), _
            StringRegExpReplace($sResponse, '(?is).*<(image_bb)>(.*?)</\1>.*', '\2'), _
            StringRegExpReplace($sResponse, '(?is).*<(image_bb2)>(.*?)</\1>.*', '\2') _
        ]
    _ArrayDisplay($aRet)
    If $iRet_Type < 0 Or $iRet_Type > 3 Then $iRet_Type = 0
    InputBox('Result - _UploadToImageShack', 'Show the image?', $aRet[$iRet_Type])
    If Not @error Then ShellExecute($aRet[$iRet_Type])
EndFunc
Func _TCPFileUpload($sLocalFile, $sHost, $sFormAction, $sFormName)
    Local $sFileRead, $sFileType, $sBoundary, $sData, $iDataSize, $sHeader, $sCommand, $iSocket, $sRecv
 
    $sFileRead = FileRead($sLocalFile)
    $sFileType = StringRegExpReplace($sLocalFile, '^.*\.', '')
    If $sFileType = 'jpg' Then $sFileType = 'jpeg'
    $sBoundary = StringFormat('----------------%s%s%smzF', @MIN, @HOUR, @SEC)
    $sData = '--' & $sBoundary & @CRLF & _
        'Content-Disposition: form-data; name="' & $sFormName & '"; filename="' & StringRegExpReplace($sLocalFile, '^.*\\', '') & '"' & @CRLF & _
        'Content-Type: image/' & $sFileType & @CRLF & @CRLF & _
        $sFileRead & @CRLF & '--' & $sBoundary & '--' & @CRLF
    $iDataSize = StringLen($sData)
    $sHeader = 'POST ' & $sFormAction & ' HTTP/1.1' & @CRLF & _
                'Host: ' & $sHost & @CRLF & _
                'Connection: close' & @CRLF & _
                'Content-Type: multipart/form-data; boundary=' & $sBoundary & @CRLF & _
                'Content-Length: ' & $iDataSize & @CRLF & @CRLF
    $sCommand = $sHeader & $sData
    TCPStartup()
    $iSocket = TCPConnect(TCPNameToIP($sHost), 80)
    TCPSend($iSocket, $sCommand)
    While 1
        $sRecv &= TCPRecv($iSocket, 20000)
        If StringLen($sRecv) <> 0 Then ExitLoop
        Sleep(50)
    WEnd
    TCPShutdown()
    Return $sRecv
EndFunc

My problem now is that the imageshack api seems to need an authenticator key to be able to use it.
I asked and got a key but I am not really sure where I must use the key.
Here is the examples but I am not really understanding them

http://code.google.com/p/imageshackapi/wiki/ImageshackAPI

Any ideas?

Edited by AutID
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...