Jump to content

TinyPicSharer v 1.0.3.4 New Version 08 June 2013


Recommended Posts

  • 1 month later...
  • Replies 54
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Popular Posts

TinyPicSharer : A simple and handy tool for capture window or picture by mouse grab and an uploader for 10 Pic Hosters ! You can also Resize, Convert, Optimize, add WaterMark to your im

Try like this #Region ;************ Includes ************ #include <WinHTTP.au3> #Include <String.au3> #include <Array.au3> #include <zlib.au3> #EndRegion ;************ In

Hello again,

I was trying again the other sites you have for upload and i can't make them work.

Here is what i tried...

#include <WinHTTP.au3>
#Include <String.au3>
#Include <Misc.au3>
#include <Array.au3>
#include <zlib.au3>


Global $__Var[9] = [0, 0, 0, 0, 16385, 8388608, 1, 0, 0]
Global $hGui, $hTab
Global $hTitleBarIcon, $hTitleBarNoIcon, $FlashIcon=True, $iIcon
Global $idTabItemUpload, $idTabItemOptimize, $idTabItemCapture, $idTabItemSettings, $idTabItemHistory, $idTabItemAbout
Global $idChkboxOptimize, $idChkboxOptimize2, $idChkboxCopy, $idChkboxOpen, $idChkboxTop, $idChkboxStart, $idChkboxMute, $idChkboxUpdate, $idChkboxUploadDirect
Global $iGuiWidth = 500, $iGuiHeight = 500, $GuiBkColor, $iRightMargin = 5, $iBottomMargin = 15
Global $hGraphic, $hImage, $hGraphic1, $hImage1, $sInImage, $sInImageOld, $idLabelLogo
Global $sTempDir = @TempDir & '\TPS'
Global $sRegTitleKey = 'TinyPicSharer'
Global $sRegKeySettings = _Iif ( StringInStr ( @OSArch, '64' ), 'HKCU64', 'HKCU' ) & '\SOFTWARE\TinyPicSharer\Settings'
Global $sRegKeyHistory = _Iif ( StringInStr ( @OSArch, '64' ), 'HKCU64', 'HKCU' ) & '\SOFTWARE\TinyPicSharer\History'
Global $sUpdateLink, $AlphaKey = 0xABABAB
Global $sHeader, $sBoundary, $sUploadKey, $sCookie, $sAuthenticityToken, $sTokenId, $sTokenSecret
Global $sImgurApiKey = 'f77d0b8cd41eb62792be0bf303e649df'
Global $sImageShackApiKey = '4CDFJKOXc6905717351511bd43f455621739c605'
Global $sTinyPicID = 'e2aabb8d555322fa'
Global $aWinListOld[1], $idComboList, $sTitles, $hBitmap, $hWndChoice, $hMouseGui, $sFilePath, $sFilePathOld
Global $HHook, $WM_LBUTTON_TEST=0, $START_X, $START_Y, $LF_RI_SIZE=0, $TO_BO_SIZE=0, $IMGE_L=0, $IMGE_T=0, $IMGE_W=0, $IMGE_H=0
Global $iOptimize, $iMute, $iOpenInBrowser, $iOnTop, $iCopy, $iCheckUpdate, $iUploadAfterDragAndDrop, $iClipAction, $iCursor=False
Global $aidRadioHost[10], $idChkboxClipboard1, $idChkboxClipboard2, $sProgPath, $idButtonFileDialog, $idPic, $idTab, $iGuiSlideDown, $iCurrentTab, $hLabelAcceptFile
Global $_StatusBar, $_StatusBarHeight=20
Global $iOriginalSize, $idGroup1, $idLabelSize, $idLabelNewSize, $idLabelType, $idLabelDimension, $sOriginalPreviewPath, $idButtonClear, $iToolTip, $hTimerInit, $iNewSize
Global $idSliderPicResize, $hSliderSize, $iSliderMaxVal = 1000, $idLabelNewDimension, $idChkboxResize, $idChkboxConvert, $idComboFormat, $idOptimizeProgress, $idButtonCancelOptimiz, $idButtonViewerOptimize
Global $aInfo2, $hGraphic3, $hBitmap2, $iPos, $tLayout2, $iSpeed, $sString, $sNewString, $TransColor, $idLabelScrollText, $idLabelScrollTextWidth=480, $idLabelScrollTextHeight = 20
Global $hBrush3, $hBrush2, $hFont2, $hFamily2, $hFormat2, $hPen2, $hGraphic2
Global $idInputWaterMarkText, $idComboWaterMarkPos, $idComboWaterMarkMargin, $idComboFontName, $idComboFontColor, $idComboFontSize, $idComboFontWeight, $idComboFontStyle
Global $idEditFontPreview, $idButtonAplyWMark, $idButtonCancelWMark, $idButtonViewerWMark, $idButtonSaveWMark
Global $idTabItemWaterMark, $idImgurItem
Global $idInputUpload1, $idInputUpload2, $idInputUpload3, $idInputUpload4, $idInputUpload5, $idUploadProgress, $idButtonUpload, $idButtonUploadOpenInBrowser, $idLabelUpload1
Global $aLogos[10] = [ $sTempDir & '\imgur5.png', $sTempDir & '\tinypic2.png', $sTempDir & '\imgbox2.png', $sTempDir & '\BayImg3.png', $sTempDir & '\Use3.png', _
$sTempDir & '\imageshack3.png', $sTempDir & '\abload2.png', $sTempDir & '\PostImage1.png', $sTempDir & '\ImgChili3.png', $sTempDir & '\imagebam3.png' ]
Global $aHostUrl[10] = [ 'http://imgur.com/', 'http://tinypic.com/', 'http://imgbox.com/', 'http://bayimg.com/', 'http://www.use.com/', _
'http://imageshack.us/', 'http://abload.de/', 'http://postimage.org/', 'http://imgchili.com/', 'http://www.imagebam.com/' ]
Global $idTrayItemHost[10], $idTrayItemTopic, $idTrayItemMyDocuments, $idTrayItemWebSites
Global $sUserAgent = 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E)'
Global $idAnimatedGifCtrl, $idLabelMessage, $idAnimatedGifCtrl2, $idLabelExtracting, $iExtract, $idTabItemExtraction, $idLabelSelect, $hListViewHistory, $iSelectedSubItem2, $iHistoryTrayTip;, $idDummy



$sFile = @ScriptDir & '\large.png'
$sPicPath = $sFile
$upload = _HostImGurUpload($sPicPath)
ConsoleWrite($upload & @CRLF)
$sLinks = _HostImGurExtractLinks ($upload)
If @error Then ConsoleWrite(@error & @CRLF)
MsgBox(0, "", $sLinks[0])

$upload2 = _HostImagebamUpload($sPicPath)
ConsoleWrite($upload2 & @CRLF)
$sLinks2 = _HostImagebamExtractLinks($upload2)
If @error Then ConsoleWrite(@error & @CRLF)
MsgBox(0, "", $sLinks2[0])




Func _PicUploadProgress ( $hRequest, $sPicPath, $sDataToSend )
If Not FileExists ( $sPicPath ) Then Return SetError ( -1 )
Local $sDatas = StringToBinary ( $sDataToSend )
Local $iNumberOfBytesToSend = 2048 ; 1024; 2048; 8192
Local $Bin, $iPercent, $iStart = 1, $iExtended = 0
While 1
$Bin = BinaryMid ( $sDatas, $iStart, $iNumberOfBytesToSend )
If BinaryLen ( $Bin ) = 0 Then Return
_WinHTTPWriteData ( $hRequest, $Bin, 1 )
If Not @error Then
$iExtended += @extended
$iPercent = Round ( ( $iExtended ) / ( StringLen ( $sDataToSend ) ) * 100, 2 )
If $iPercent > 97 Then $iPercent = 97
$iStart += $iNumberOfBytesToSend
Else
$Bin = 0
Return SetError ( 1 )
EndIf
WEnd
EndFunc ;==> _PicUploadProgress ()

Func _PicReadData ( $sPicPath )
If Not FileExists ( $sPicPath ) Then Return SetError ( -1 )
Local $hFile = FileOpen ( $sPicPath )
If $hFile = -1 Then Return SetError ( 1 )
Local $sData = FileRead ( $hFile )
If @error Then Return SetError ( 2 )
FileClose ( $hFile )
Return $sData
EndFunc ;==> _PicReadData ()

Func _GetFullNameByFullPath ( $sFullPath )
Local $aFileName = StringSplit ( $sFullPath, '\' )
If Not @error Then Return $aFileName[$aFileName[0]]
Return SetError ( 1 )
EndFunc ;==> _GetFullNameByFullPath ()

Func _GetExtByFullPath ( $sFullPath )
Local $aFileName = StringSplit ( $sFullPath, '.' )
If Not @error Then Return $aFileName[$aFileName[0]]
Return SetError ( 1 )
EndFunc ;==> _GetExtByFullPath ()

Func _PicGetContentType ( $sPicPath )
If Not FileExists ( $sPicPath ) Then Return SetError ( -1 )
Local $sExt = _GetExtByFullPath ( $sPicPath )
If @error Or $sExt = '' Then Return SetError ( 1 )
Local $sContentType
Switch $sExt
Case 'jpg', 'jpe', 'jpeg'
$sContentType = 'Content-Type: image/jpeg' ; ie 'Content-Type: image/pjpeg'
Case 'gif'
$sContentType = 'Content-Type: image/gif'
Case 'bmp'
$sContentType = 'Content-Type: image/bmp'
Case 'png'
$sContentType = 'Content-Type: image/png' ; ie Content-Type: image/x-png
Case 'tif', 'tiff'
$sContentType = 'Content-Type: image/tiff'
Case Else
Return SetError ( 2 )
EndSwitch
Return $sContentType
EndFunc ;==> _PicGetContentType ()


Func _HostImagebamExtractLinks ( $HtmlData )
;~ Return Links Array
;~ [0] Link only ( viewer only, not download link)
;~ [1] Thumb
;~ [2] BBCode
;~ [3] HTML
$HtmlData = StringMid ( $HtmlData, StringInStr ( $HtmlData, 'dlinput_container', 0, 1 ) - StringLen ( 'dlinput_container' ) -1 )
Local $aRet = StringRegExp ( StringReplace ( $HtmlData, @LF, '' ), "(?s)(?i)dlinput_container(.*?)</div>", 3 )
If Not @error Then
Local $aLinks[3], $aRet1
For $i = 0 To UBound ( $aRet ) -2
$aRet1 = StringRegExp ( $aRet[$i], "(?s)(?i)value='(.*?)>", 3 )
If Not @error Then
$aRet1[0] = StringStripWS ( StringTrimRight ( $aRet1[0], 1 ), 1+2 )
$aLinks[$i] = $aRet1[0]
EndIf
Next
_ArrayReverse ( $aLinks )
Local $sUrl = _StringBetween ( $aLinks[1], '' )
If Not @error Then
_ArrayInsert ( $aLinks, 1, $sUrl[0] )
Else
Return SetError ( 2 )
EndIf
If $aLinks[UBound ( $aLinks )-1] <> '' Then
Return $aLinks
Else
Return SetError ( 3 )
EndIf
Else
Return SetError ( 1 )
EndIf
EndFunc ;==> _HostImagebamExtractLinks ()

Func _HostImagebamSetDataToSend ( $sPicPath )
Local $sData = _PicReadData ( $sPicPath )
If @error Then Return SetError ( 1 )
Local $sImageName = _GetFullNameByFullPath ( $sPicPath )
If @error Or $sImageName = '' Then Return SetError ( 2 )
Local $sContentType = _PicGetContentType ( $sPicPath )
If @error Then Return SetError ( 3 )
Local $sCdfdn = 'Content-Disposition: form-data; name'
Local $sCtaos = 'Content-Type: application/octet-stream'
Local $sString = $sBoundary & @CRLF & _
$sCdfdn & '="file[]"; filename="' & $sImageName & '"' & @CRLF & _
$sContentType & @CRLF & @CRLF & $sData & @CRLF & $sBoundary & @CRLF
For $i = 1 To 29
$sString &= $sCdfdn & '="file[]"; filename=""' & @CRLF & _
$sCtaos & @CRLF & @CRLF & @CRLF & $sBoundary & @CRLF
Next
$sString &= $sCdfdn & '="content_type"' & @CRLF & @CRLF & '0' & @CRLF & $sBoundary & @CRLF & _
$sCdfdn & '="thumb_size"' & @CRLF & @CRLF & '100' & @CRLF & $sBoundary & @CRLF & _
$sCdfdn & '="thumb_aspect_ratio"' & @CRLF & @CRLF & 'resize' & @CRLF & $sBoundary & @CRLF & _
$sCdfdn & '="thumb_file_type"' & @CRLF & @CRLF & 'jpg' & @CRLF & $sBoundary & '--'
Return SetError ( 0, '', $sString )
EndFunc ;==> _HostImagebamSetDataToSend ()

Func _HostImagebamUpload ( $sPicPath )
Local $hOpen, $hConnect, $hRequest, $sHost, $sDataToSend, $sReceivedData, $iError, $sResponse, $sPostData, $sContentType
$sHost = 'www.imagebam.com'
$hOpen = _WinHttpOpen ( $sUserAgent )
If @error Then
SetError ( 1 )
Else
$hConnect = _WinHttpConnect ( $hOpen, $sHost )
If @error Then
SetError ( 2 )
Else
$hRequest = _WinHttpOpenRequest ( $hConnect, 'POST', '/sys/upload/save', 'HTTP/1.1' )
If @error Then
SetError ( 3 )
Else
_WinHttpSetTimeouts ( $hRequest, 10000, 60000, 90000, 90000 )
$sDataToSend = _HostImagebamSetDataToSend ( $sPicPath )
_WinHttpAddRequestHeaders ( $hRequest, 'Accept: application/x-ms-application, image/jpeg, application/xaml+xml, image/gif, image/pjpeg, application/x-ms-xbap, application/x-silverlight, */*' )
_WinHttpAddRequestHeaders ( $hRequest, 'Referer: http://www.imagebam.com/basic-upload' )
_WinHttpAddRequestHeaders ( $hRequest, 'Accept-Encoding: gzip, deflate' )
_WinHttpAddRequestHeaders ( $hRequest, 'Connection: Keep-Alive' )
_WinHttpAddRequestHeaders ( $hRequest, 'Cache-Control: no-cache' )
$sContentType = 'Content-Type: multipart/form-data; boundary=' & StringTrimLeft ( $sBoundary, 2 )
_WinHttpSendRequest ( $hRequest, $sContentType, $WINHTTP_NO_REQUEST_DATA, StringLen ( $sDataToSend ) )
If @error Then
SetError ( 4 )
Else
_PicUploadProgress ( $hRequest, $sPicPath, $sDataToSend )
If Not @error Then
$hTimerInit = TimerInit ()
_WinHttpReceiveResponse ( $hRequest )
If @error Then
SetError ( 5 )
Else
If _WinHttpQueryDataAvailable ( $hRequest ) Then
$sReceivedData = Binary ( '' )
While 1
$sReceivedData &= _WinHttpReadData ( $hRequest , 2 )
If Not @extended Then
SetError ( 0 )
ExitLoop ;~
EndIf
WEnd
$sReceivedData = BinaryToString ( _ZLIB_GZUncompress ( $sReceivedData ) )
If StringInStr ( $sReceivedData, 'box_error' ) Then SetError ( 6 ) ; The thumbnail for the file pic.jpg could not be created.
Else
SetError ( 7 )
EndIf
EndIf
Else
SetError ( 8 )
EndIf
EndIf
EndIf
EndIf
EndIf
$iError = @error
If $hRequest Then _WinHttpCloseHandle ( $hRequest )
If $hConnect Then _WinHttpCloseHandle ( $hConnect )
If $hOpen Then _WinHttpCloseHandle ( $hOpen )
Return SetError ( $iError, 0, $sReceivedData )
EndFunc

Func _HostImGurExtractLinks ( $XmlData )
Local $aImGurChars[5] = ['original', 'imgur_page', 'delete_page', 'small_square', 'large_thumbnail' ]
Local $aLinks[5]
For $i = 0 To UBound ( $aLinks ) -1
$aLinks[$i] = StringRegExpReplace ( $XmlData, '(?is).*<(' & $aImGurChars[$i] & ')>(.*?)</\1>.*', '\2' )
Next
If $aLinks[4] <> '' Then
If $aLinks[UBound ( $aLinks )-1] <> '' Then
Local $sTmp = $aLinks[1]
$aLinks[1] = $aLinks[3]
$aLinks[3] = $sTmp
$sTmp = $aLinks[4]
$aLinks[4] = $aLinks[2]
$aLinks[2] = $sTmp
Return $aLinks
Else
Return SetError ( 3 )
EndIf
Else
Return SetError ( 1 )
EndIf
EndFunc ;==> _HostImGurExtractLinks ()

Func _HostImGurSetDataToSend ( $sPicPath )
Local $sData = _PicReadData ( $sPicPath )
If @error Then Return SetError ( 1 )
Local $sImageName = _GetFullNameByFullPath ( $sPicPath )
If @error Or $sImageName = '' Then Return SetError ( 2 )
Local $sContentType = _PicGetContentType ( $sPicPath )
If @error Then Return SetError ( 3 )
Return SetError ( 0, '', $sBoundary & @CRLF & _
'Content-Disposition: form-data; name="image"; filename="' & $sImageName & '"' & @CRLF & _
$sContentType & @CRLF & @CRLF & $sData & @CRLF & $sBoundary & @CRLF & _
'Content-Disposition: form-data; name="key"' & @CRLF & @CRLF & $sImgurApiKey & @CRLF & $sBoundary )
EndFunc ;==> _HostImGurSetDataToSend ()

Func _HostImGurUpload ( $sPicPath )
Local $hOpen, $hConnect, $hRequest, $sHost, $sDataToSend, $sReceivedData, $iError, $sResponse, $sPostData, $sContentType
$sHost = 'api.imgur.com'
$hOpen = _WinHttpOpen ( $sUserAgent )
If @error Then
SetError ( 1 )
Else
$hConnect = _WinHttpConnect ( $hOpen, $sHost )
If @error Then
SetError ( 2 )
Else
$hRequest = _WinHttpOpenRequest ( $hConnect, 'POST', '/2/upload.xml', 'HTTP/1.1' )
If @error Then
SetError ( 3 )
Else
_WinHttpSetTimeouts ( $hRequest, 10000, 60000, 90000, 90000 )
$sDataToSend = _HostImGurSetDataToSend ( $sPicPath )
_WinHttpAddRequestHeaders ( $hRequest, 'Accept: */*' )
_WinHttpAddRequestHeaders ( $hRequest, 'Expect: 100-continue' )
$sContentType = 'Content-Type: multipart/form-data; boundary=' & StringTrimLeft ( $sBoundary, 2 )
_WinHttpSendRequest ( $hRequest, $sContentType, $WINHTTP_NO_REQUEST_DATA, StringLen ( $sDataToSend ) )
If @error Then
SetError ( 4 )
Else
_PicUploadProgress ( $hRequest, $sPicPath, $sDataToSend )
If Not @error Then
$hTimerInit = TimerInit ()
_WinHttpReceiveResponse ( $hRequest )
If @error Then
SetError ( 5 )
Else
If _WinHttpQueryDataAvailable ( $hRequest ) Then
$sReceivedData = ''
While 1
$sReceivedData &= _WinHttpReadData ( $hRequest )
If Not @extended Then
SetError ( 0 )
ExitLoop
EndIf
WEnd
If StringInStr ( $sReceivedData, 'error' ) Then SetError ( 6 )
Else
SetError ( 7 )
EndIf
EndIf
Else
SetError ( 8 )
EndIf
EndIf
EndIf
EndIf
EndIf
$iError = @error
If $hRequest Then _WinHttpCloseHandle ( $hRequest )
If $hConnect Then _WinHttpCloseHandle ( $hConnect )
If $hOpen Then _WinHttpCloseHandle ( $hOpen )
Return SetError ( $iError, 0, $sReceivedData )
EndFunc

I have added all the global vars, copy paste :D

Link to post
Share on other sites

Hello again,

I was trying again the other sites you have for upload and i can't make them work.

I have added all the global vars, copy paste :D

 

Try like this

#Region    ;************ Includes ************
#include <WinHTTP.au3>
#Include <String.au3>
#include <Array.au3>
#include <zlib.au3>
#EndRegion ;************ Includes ************

Global $sBoundary = '--' & _GenerateBoundary ( 30 )
Global $sImgurApiKey = 'f77d0b8cd41eb62792be0bf303e649df'
Global $sUserAgent = 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E)'

$sPicPath = @ScriptDir & '\large.png'

$upload = _HostImGurUpload ( $sPicPath )
If Not @error Then
    $aLinks = _HostImGurExtractLinks  ( $upload )
    If Not @error Then MsgBox ( 0, "Picture Link : ", $aLinks[0] )
EndIf

$upload2 = _HostImagebamUpload ( $sPicPath )
If Not @error Then
    $aLinks2 = _HostImagebamExtractLinks ( $upload2 )
    If Not @error Then MsgBox ( 0, "Picture Link : ", $aLinks2[0] )
EndIf

Func _GenerateBoundary ( $iLen )
    Local $sString = ''
    Do
        Switch Random ( 1, 3, 1 )
            Case 1
                $sString &= Chr ( Random ( 48, 57, 1 ) )  ; 0 to 9
            Case 2
                $sString &= Chr ( Random ( 65, 90, 1 ) )  ; A to Z
            Case 3
                $sString &= Chr ( Random ( 97, 122, 1 ) ) ; a to z
        EndSwitch
    Until StringLen ( $sString ) = $iLen
    Return $sString
EndFunc ;==> _GenerateBoundary ()

Func _GetExtByFullPath ( $sFullPath )
    Local $aFileName = StringSplit ( $sFullPath, '.' )
    If Not @error Then Return $aFileName[$aFileName[0]]
    Return SetError ( 1 )
EndFunc ;==> _GetExtByFullPath ()

Func _GetFullNameByFullPath ( $sFullPath )
    Local $aFileName = StringSplit ( $sFullPath, '\' )
    If Not @error Then Return $aFileName[$aFileName[0]]
    Return SetError ( 1 )
EndFunc ;==> _GetFullNameByFullPath ()

Func _HostImagebamExtractLinks ( $HtmlData )
;~  Return Links Array
;~  [0] Link only ( viewer only, not download link)
;~  [1] Thumb
;~  [2] BBCode
;~  [3] HTML
    $HtmlData = StringMid ( $HtmlData, StringInStr ( $HtmlData, 'dlinput_container', 0, 1 ) - StringLen ( 'dlinput_container' ) -1 )
    Local $aRet = StringRegExp ( StringReplace ( $HtmlData, @LF, '' ), "(?s)(?i)dlinput_container(.*?)</div>", 3 )
    If Not @error Then
        Local $aLinks[3], $aRet1
        For $i = 0 To UBound ( $aRet ) -2
            $aRet1 = StringRegExp ( $aRet[$i], "(?s)(?i)value='(.*?)>", 3 )
            If Not @error Then
                $aRet1[0] = StringStripWS ( StringTrimRight ( $aRet1[0], 1 ), 1+2 )
                $aLinks[$i] = $aRet1[0]
            EndIf
        Next
        _ArrayReverse ( $aLinks )
        Local $sUrl = _StringBetween ( $aLinks[1], '[IMG]', '[/IMG]' )
        If Not @error Then
            _ArrayInsert ( $aLinks, 1, $sUrl[0] )
        Else
            Return SetError ( 2 )
        EndIf
        If $aLinks[UBound ( $aLinks )-1] <> '' Then
            Return $aLinks
        Else
            Return SetError ( 3 )
        EndIf
    Else
        Return SetError ( 1 )
    EndIf
EndFunc ;==> _HostImagebamExtractLinks ()

Func _HostImagebamSetDataToSend ( $sPicPath )
    Local $sData = _PicReadData ( $sPicPath )
    If @error Then Return SetError ( 1 )
    Local $sImageName = _GetFullNameByFullPath ( $sPicPath )
    If @error Or $sImageName = '' Then Return SetError ( 2 )
    Local $sContentType = _PicGetContentType ( $sPicPath )
    If @error Then Return SetError ( 3 )
    Local $sCdfdn = 'Content-Disposition: form-data; name'
    Local $sCtaos = 'Content-Type: application/octet-stream'
    Local $sString = $sBoundary & @CRLF & _
        $sCdfdn & '="file[]"; filename="' & $sImageName & '"' & @CRLF & _
        $sContentType & @CRLF & @CRLF & $sData & @CRLF & $sBoundary & @CRLF
    For $i = 1 To 29
        $sString &= $sCdfdn & '="file[]"; filename=""' & @CRLF & _
            $sCtaos & @CRLF & @CRLF & @CRLF & $sBoundary & @CRLF
    Next
    $sString &= $sCdfdn & '="content_type"' & @CRLF & @CRLF & '0' & @CRLF & $sBoundary & @CRLF & _
        $sCdfdn & '="thumb_size"' & @CRLF & @CRLF & '100' & @CRLF & $sBoundary & @CRLF & _
        $sCdfdn & '="thumb_aspect_ratio"' & @CRLF & @CRLF & 'resize' & @CRLF & $sBoundary & @CRLF & _
        $sCdfdn & '="thumb_file_type"' & @CRLF & @CRLF & 'jpg' & @CRLF & $sBoundary & '--'
    Return SetError ( 0, '', $sString )
EndFunc ;==> _HostImagebamSetDataToSend ()

Func _HostImagebamUpload ( $sPicPath )
    Local $hOpen, $hConnect, $hRequest, $sHost, $sDataToSend, $sReceivedData, $iError, $sResponse, $sPostData, $sContentType
    $sHost = 'www.imagebam.com'
    $hOpen = _WinHttpOpen ( $sUserAgent )
    If @error Then
        SetError ( 1 )
    Else
        $hConnect = _WinHttpConnect ( $hOpen, $sHost )
        If @error Then
            SetError ( 2 )
        Else
            $hRequest = _WinHttpOpenRequest ( $hConnect, 'POST', '/sys/upload/save', 'HTTP/1.1' )
            If @error Then
                SetError ( 3 )
            Else
                _WinHttpSetTimeouts ( $hRequest, 10000, 60000, 90000, 90000 )
                $sDataToSend = _HostImagebamSetDataToSend ( $sPicPath )
                _WinHttpAddRequestHeaders ( $hRequest, 'Accept: application/x-ms-application, image/jpeg, application/xaml+xml, image/gif, image/pjpeg, application/x-ms-xbap, application/x-silverlight, */*' )
                _WinHttpAddRequestHeaders ( $hRequest, 'Referer: http://www.imagebam.com/basic-upload' )
                _WinHttpAddRequestHeaders ( $hRequest, 'Accept-Encoding: gzip, deflate' )
                _WinHttpAddRequestHeaders ( $hRequest, 'Connection: Keep-Alive' )
                _WinHttpAddRequestHeaders ( $hRequest, 'Cache-Control: no-cache' )
                $sContentType = 'Content-Type: multipart/form-data; boundary=' & StringTrimLeft ( $sBoundary, 2 )
                _WinHttpSendRequest ( $hRequest, $sContentType, $WINHTTP_NO_REQUEST_DATA, StringLen ( $sDataToSend ) )
                If @error Then
                    SetError ( 4 )
                Else
                    _PicUploadProgress ( $hRequest, $sPicPath, $sDataToSend )
                    If Not @error Then
                        _WinHttpReceiveResponse ( $hRequest )
                        If @error Then
                            SetError ( 5 )
                        Else
                            If _WinHttpQueryDataAvailable ( $hRequest ) Then
                                $sReceivedData = Binary ( '' )
                                While 1
                                    $sReceivedData &= _WinHttpReadData ( $hRequest , 2 )
                                    If Not @extended Then
                                        SetError ( 0 )
                                        ExitLoop ;~
                                    EndIf
                                WEnd
                                $sReceivedData = BinaryToString ( _ZLIB_GZUncompress ( $sReceivedData ) )
                                If StringInStr ( $sReceivedData, 'box_error' ) Then SetError ( 6 ) ; The thumbnail for the file pic.jpg could not be created.
                            Else
                                SetError ( 7 )
                            EndIf
                        EndIf
                    Else
                        SetError ( 8 )
                    EndIf
                EndIf
            EndIf
        EndIf
    EndIf
    $iError = @error
    If $hRequest Then _WinHttpCloseHandle ( $hRequest )
    If $hConnect Then _WinHttpCloseHandle ( $hConnect )
    If $hOpen Then _WinHttpCloseHandle ( $hOpen )
    Return SetError ( $iError, 0, $sReceivedData )
EndFunc ;==> _HostImagebamUpload ()

Func _HostImGurExtractLinks ( $XmlData )
    Local $aImGurChars[5] = ['original', 'imgur_page', 'delete_page', 'small_square', 'large_thumbnail' ]
    Local $aLinks[5]
    For $i = 0 To UBound ( $aLinks ) -1
        $aLinks[$i] = StringRegExpReplace ( $XmlData, '(?is).*<(' & $aImGurChars[$i] & ')>(.*?)</\1>.*', '\2' )
    Next
    If $aLinks[4] <> '' Then
        If $aLinks[UBound ( $aLinks )-1] <> '' Then
            Local $sTmp = $aLinks[1]
            $aLinks[1] = $aLinks[3]
            $aLinks[3] = $sTmp
            $sTmp = $aLinks[4]
            $aLinks[4] = $aLinks[2]
            $aLinks[2] = $sTmp
            Return $aLinks
        Else
            Return SetError ( 3 )
        EndIf
    Else
        Return SetError ( 1 )
    EndIf
EndFunc ;==> _HostImGurExtractLinks ()

Func _HostImGurSetDataToSend ( $sPicPath )
    Local $sData = _PicReadData ( $sPicPath )
    If @error Then Return SetError ( 1 )
    Local $sImageName = _GetFullNameByFullPath ( $sPicPath )
    If @error Or $sImageName = '' Then Return SetError ( 2 )
    Local $sContentType = _PicGetContentType ( $sPicPath )
    If @error Then Return SetError ( 3 )
    Return SetError ( 0, '', $sBoundary & @CRLF & _
        'Content-Disposition: form-data; name="image"; filename="' & $sImageName & '"' & @CRLF & _
        $sContentType & @CRLF & @CRLF & $sData & @CRLF & $sBoundary & @CRLF & _
        'Content-Disposition: form-data; name="key"' & @CRLF & @CRLF & $sImgurApiKey & @CRLF & $sBoundary )
EndFunc ;==> _HostImGurSetDataToSend ()

Func _HostImGurUpload ( $sPicPath )
    Local $hOpen, $hConnect, $hRequest, $sHost, $sDataToSend, $sReceivedData, $iError, $sResponse, $sPostData, $sContentType
    $sHost = 'api.imgur.com'
    $hOpen = _WinHttpOpen ( $sUserAgent )
    If @error Then
        SetError ( 1 )
    Else
        $hConnect = _WinHttpConnect ( $hOpen, $sHost )
        If @error Then
            SetError ( 2 )
        Else
            $hRequest = _WinHttpOpenRequest ( $hConnect, 'POST', '/2/upload.xml', 'HTTP/1.1' )
            If @error Then
                SetError ( 3 )
            Else
                _WinHttpSetTimeouts ( $hRequest, 10000, 60000, 90000, 90000 )
                $sDataToSend = _HostImGurSetDataToSend ( $sPicPath )
                _WinHttpAddRequestHeaders ( $hRequest, 'Accept: */*' )
                _WinHttpAddRequestHeaders ( $hRequest, 'Expect: 100-continue' )
                $sContentType = 'Content-Type: multipart/form-data; boundary=' & StringTrimLeft ( $sBoundary, 2 )
                _WinHttpSendRequest ( $hRequest, $sContentType, $WINHTTP_NO_REQUEST_DATA, StringLen ( $sDataToSend ) )
                If @error Then
                    SetError ( 4 )
                Else
                    _PicUploadProgress ( $hRequest, $sPicPath, $sDataToSend )
                    If Not @error Then
                        _WinHttpReceiveResponse ( $hRequest )
                        If @error Then
                            SetError ( 5 )
                        Else
                            If _WinHttpQueryDataAvailable ( $hRequest ) Then
                                $sReceivedData = ''
                                While 1
                                    $sReceivedData &= _WinHttpReadData ( $hRequest )
                                    If Not @extended Then
                                        SetError ( 0 )
                                        ExitLoop
                                    EndIf
                                WEnd
                                If StringInStr ( $sReceivedData, 'error' ) Then SetError ( 6 )
                            Else
                                SetError ( 7 )
                            EndIf
                        EndIf
                    Else
                        SetError ( 8 )
                    EndIf
                EndIf
            EndIf
        EndIf
    EndIf
    $iError = @error
    If $hRequest Then _WinHttpCloseHandle ( $hRequest )
    If $hConnect Then _WinHttpCloseHandle ( $hConnect )
    If $hOpen Then _WinHttpCloseHandle ( $hOpen )
    Return SetError ( $iError, 0, $sReceivedData )
EndFunc ;==> _HostImGurUpload ()

Func _PicGetContentType ( $sPicPath )
    If Not FileExists ( $sPicPath ) Then Return SetError ( -1 )
    Local $sExt = _GetExtByFullPath ( $sPicPath )
    If @error Or $sExt = '' Then Return SetError ( 1 )
    Local $sContentType
    Switch $sExt
        Case 'jpg', 'jpe', 'jpeg'
            $sContentType = 'Content-Type: image/jpeg' ; ie 'Content-Type: image/pjpeg'
        Case 'gif'
            $sContentType = 'Content-Type: image/gif'
        Case 'bmp'
            $sContentType = 'Content-Type: image/bmp'
        Case 'png'
            $sContentType = 'Content-Type: image/png' ; ie Content-Type: image/x-png
        Case 'tif', 'tiff'
            $sContentType = 'Content-Type: image/tiff'
        Case Else
            Return SetError ( 2 )
    EndSwitch
    Return $sContentType
EndFunc ;==> _PicGetContentType ()

Func _PicReadData ( $sPicPath )
    If Not FileExists ( $sPicPath ) Then Return SetError ( -1 )
    Local $hFile = FileOpen ( $sPicPath )
    If $hFile = -1 Then Return SetError ( 1 )
    Local $sData = FileRead ( $hFile )
    If @error Then Return SetError ( 2 )
    FileClose ( $hFile )
    Return $sData
EndFunc ;==> _PicReadData ()

Func _PicUploadProgress ( $hRequest, $sPicPath, $sDataToSend )
    If Not FileExists ( $sPicPath ) Then Return SetError ( -1 )
    Local $sDatas = StringToBinary ( $sDataToSend )
    Local $iNumberOfBytesToSend = 2048
    Local $Bin, $iPercent, $iStart = 1, $iExtended = 0
    While 1
        $Bin = BinaryMid ( $sDatas, $iStart, $iNumberOfBytesToSend )
        If BinaryLen ( $Bin ) = 0 Then Return
        _WinHTTPWriteData ( $hRequest, $Bin, 1 )
        If Not @error Then
            $iExtended += @extended
            $iPercent =  Round ( ( $iExtended  ) / ( StringLen ( $sDataToSend ) ) * 100, 2 )
            ConsoleWrite ( '-->-- [' & StringFormat ( '%03i', @ScriptLineNumber ) & '][' & @HOUR & @MIN & @SEC & '] $iPercent : ' & $iPercent & @Crlf )
            If $iPercent > 97 Then $iPercent = 97
            $iStart += $iNumberOfBytesToSend
        Else
            $Bin = 0
            Return SetError ( 1 )
        EndIf
    WEnd
EndFunc ;==> _PicUploadProgress ()

You forgot to set the value of the $sBoundary variable !  o:)

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Link to post
Share on other sites

Oups :)

What about this?

$upload4 = _HostTinyPicUpload ( $sPicPath )
If @error Then ConsoleWrite("7 " & @error & @CRLF)
$sLinks4 = _HostTinyPicExtractLinks ( $upload4 )
If @error Then
ConsoleWrite("8 " & @error & @CRLF)
Else
ConsoleWrite($sLinks4[0] & @LF)
EndIf
Does it need the _PicUploadStart() functionto update a key?
Link to post
Share on other sites

Oups :)

What about this?

$upload4 = _HostTinyPicUpload ( $sPicPath )
If @error Then ConsoleWrite("7 " & @error & @CRLF)
$sLinks4 = _HostTinyPicExtractLinks ( $upload4 )
If @error Then
ConsoleWrite("8 " & @error & @CRLF)
Else
ConsoleWrite($sLinks4[0] & @LF)
EndIf
Does it need the _PicUploadStart() functionto update a key?

 

 

Without the TinyPic UploadKey returned, upload can not work. :)

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Link to post
Share on other sites
  • 1 year later...

Nice work with TinyPicSharer!

I created a UDF from your script but I was wondering if it is possible to upload to a specific user account on ImageBam?

#include <WinHTTP.au3>
#include <String.au3>
#include <Array.au3>
#include <zlib.au3>

Local $sBoundary = '--' & _GenerateBoundary(30)

; #FUNCTION# ====================================================================================================================
; Name...........: _ImagebamUpload
; Description ...: Upload image file to ImageBam.
; Syntax.........: _ImagebamUpload( $sPicPath )
; Parameters ....: $sPicPath     - Image path to upload
; Return values .: Success - Returns the link from ImageBam
;                  Failure - 0, sets @error:
;                  |1 - couldn't upload image
;                  |2 - couldn't get link
; Author ........: wakillon
; Modified.......: oapjr
; Remarks .......:
; Related .......:
; Link ..........; http://www.autoitscript.com/forum/topic/122168-tinypicsharer-v-1034-new-version-08-june-2013
; Example .......; No
; ===============================================================================================================================
Func _ImagebamUpload($sPicPath)
    $upload = _HostImagebamUpload($sPicPath)
    If @error Then
        SetError(1)
    Else
        $aLinks = _HostImagebamExtractLinks($upload)
        If @error Then
            SetError(2)
        Else
            Return $aLinks[0]
        EndIf
    EndIf
    Return 0
EndFunc   ;==>_ImagebamUpload

Func _HostImagebamUpload($sPicPath)
    Local $hOpen, $hConnect, $hRequest, $sHost, $sDataToSend, $sReceivedData, $iError, $sResponse, $sPostData, $sContentType
    Local $sUserAgent = 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E)'
    $sHost = 'www.imagebam.com'
    $hOpen = _WinHttpOpen($sUserAgent)
    If @error Then
        SetError(1)
    Else
        $hConnect = _WinHttpConnect($hOpen, $sHost)
        If @error Then
            SetError(2)
        Else
            $hRequest = _WinHttpOpenRequest($hConnect, 'POST', '/sys/upload/save', 'HTTP/1.1')
            If @error Then
                SetError(3)
            Else
                _WinHttpSetTimeouts($hRequest, 10000, 60000, 90000, 90000)
                $sDataToSend = _HostImagebamSetDataToSend($sPicPath)
                _WinHttpAddRequestHeaders($hRequest, 'Accept: application/x-ms-application, image/jpeg, application/xaml+xml, image/gif, image/pjpeg, application/x-ms-xbap, application/x-silverlight, */*')
                _WinHttpAddRequestHeaders($hRequest, 'Referer: http://www.imagebam.com/basic-upload')
                _WinHttpAddRequestHeaders($hRequest, 'Accept-Encoding: gzip, deflate')
                _WinHttpAddRequestHeaders($hRequest, 'Connection: Keep-Alive')
                _WinHttpAddRequestHeaders($hRequest, 'Cache-Control: no-cache')
                $sContentType = 'Content-Type: multipart/form-data; boundary=' & StringTrimLeft($sBoundary, 2)
                _WinHttpSendRequest($hRequest, $sContentType, $WINHTTP_NO_REQUEST_DATA, StringLen($sDataToSend))
                If @error Then
                    SetError(4)
                Else
                    _PicUploadProgress($hRequest, $sPicPath, $sDataToSend)
                    If Not @error Then
                        _WinHttpReceiveResponse($hRequest)
                        If @error Then
                            SetError(5)
                        Else
                            If _WinHttpQueryDataAvailable($hRequest) Then
                                $sReceivedData = Binary('')
                                While 1
                                    $sReceivedData &= _WinHttpReadData($hRequest, 2)
                                    If Not @extended Then
                                        SetError(0)
                                        ExitLoop ;~
                                    EndIf
                                WEnd
                                $sReceivedData = BinaryToString( _ZLIB_GZUncompress($sReceivedData))
                                If StringInStr($sReceivedData, 'box_error') Then SetError(6) ; The thumbnail for the file pic.jpg could not be created.
                            Else
                                SetError(7)
                            EndIf
                        EndIf
                    Else
                        SetError(8)
                    EndIf
                EndIf
            EndIf
        EndIf
    EndIf
    $iError = @error
    If $hRequest Then _WinHttpCloseHandle($hRequest)
    If $hConnect Then _WinHttpCloseHandle($hConnect)
    If $hOpen Then _WinHttpCloseHandle($hOpen)
    Return SetError($iError, 0, $sReceivedData)
EndFunc   ;==>_HostImagebamUpload

Func _HostImagebamExtractLinks($HtmlData)
;~  Return Links Array
;~  [0] Link only ( viewer only, not download link)
;~  [1] Thumb
;~  [2] BBCode
;~  [3] HTML
    $HtmlData = StringMid($HtmlData, StringInStr($HtmlData, 'dlinput_container', 0, 1) - StringLen('dlinput_container') - 1)
    Local $aRet = StringRegExp(StringReplace($HtmlData, @LF, ''), "(?s)(?i)dlinput_container(.*?)</div>", 3)
    If Not @error Then
        Local $aLinks[3], $aRet1
        For $i = 0 To UBound($aRet) - 2
            $aRet1 = StringRegExp($aRet[$i], "(?s)(?i)value='(.*?)>", 3)
            If Not @error Then
                $aRet1[0] = StringStripWS(StringTrimRight($aRet1[0], 1), 1 + 2)
                $aLinks[$i] = $aRet1[0]
            EndIf
        Next
        _ArrayReverse($aLinks)
        Local $sUrl = _StringBetween($aLinks[1], '[img]', '[/IMG]')
        If Not @error Then
            _ArrayInsert($aLinks, 1, $sUrl[0])
        Else
            Return SetError(2)
        EndIf
        If $aLinks[UBound($aLinks) - 1] <> '' Then
            Return $aLinks
        Else
            Return SetError(3)
        EndIf
    Else
        Return SetError(1)
    EndIf
EndFunc   ;==>_HostImagebamExtractLinks

Func _GenerateBoundary($iLen)
    Local $sString = ''
    Do
        Switch Random(1, 3, 1)
            Case 1
                $sString &= Chr(Random(48, 57, 1)) ; 0 to 9
            Case 2
                $sString &= Chr(Random(65, 90, 1)) ; A to Z
            Case 3
                $sString &= Chr(Random(97, 122, 1)) ; a to z
        EndSwitch
    Until StringLen($sString) = $iLen
    Return $sString
EndFunc   ;==>_GenerateBoundary

Func _HostImagebamSetDataToSend($sPicPath)
    Local $sData = _PicReadData($sPicPath)
    If @error Then Return SetError(1)
    Local $sImageName = _GetFullNameByFullPath($sPicPath)
    If @error Or $sImageName = '' Then Return SetError(2)
    Local $sContentType = _PicGetContentType($sPicPath)
    If @error Then Return SetError(3)
    Local $sCdfdn = 'Content-Disposition: form-data; name'
    Local $sCtaos = 'Content-Type: application/octet-stream'
    Local $sString = $sBoundary & @CRLF & _
            $sCdfdn & '="file[]"; filename="' & $sImageName & '"' & @CRLF & _
            $sContentType & @CRLF & @CRLF & $sData & @CRLF & $sBoundary & @CRLF
    For $i = 1 To 29
        $sString &= $sCdfdn & '="file[]"; filename=""' & @CRLF & _
                $sCtaos & @CRLF & @CRLF & @CRLF & $sBoundary & @CRLF
    Next
    $sString &= $sCdfdn & '="content_type"' & @CRLF & @CRLF & '0' & @CRLF & $sBoundary & @CRLF & _
            $sCdfdn & '="thumb_size"' & @CRLF & @CRLF & '100' & @CRLF & $sBoundary & @CRLF & _
            $sCdfdn & '="thumb_aspect_ratio"' & @CRLF & @CRLF & 'resize' & @CRLF & $sBoundary & @CRLF & _
            $sCdfdn & '="thumb_file_type"' & @CRLF & @CRLF & 'jpg' & @CRLF & $sBoundary & '--'
    Return SetError(0, '', $sString)
EndFunc   ;==>_HostImagebamSetDataToSend

Func _PicUploadProgress($hRequest, $sPicPath, $sDataToSend)
    If Not FileExists($sPicPath) Then Return SetError(-1)
    Local $sDatas = StringToBinary($sDataToSend)
    Local $iNumberOfBytesToSend = 2048
    Local $Bin, $iPercent, $iStart = 1, $iExtended = 0
    While 1
        $Bin = BinaryMid($sDatas, $iStart, $iNumberOfBytesToSend)
        If BinaryLen($Bin) = 0 Then Return
        _WinHTTPWriteData($hRequest, $Bin, 1)
        If Not @error Then
            $iExtended += @extended
            $iPercent = Round(($iExtended) / (StringLen($sDataToSend)) * 100, 2)
            ConsoleWrite('-->-- [' & StringFormat('%03i', @ScriptLineNumber) & '][' & @HOUR & @MIN & @SEC & '] $iPercent : ' & $iPercent & @CRLF)
            If $iPercent > 97 Then $iPercent = 97
            $iStart += $iNumberOfBytesToSend
        Else
            $Bin = 0
            Return SetError(1)
        EndIf
    WEnd
EndFunc   ;==>_PicUploadProgress

Func _PicGetContentType($sPicPath)
    If Not FileExists($sPicPath) Then Return SetError(-1)
    Local $sExt = _GetExtByFullPath($sPicPath)
    If @error Or $sExt = '' Then Return SetError(1)
    Local $sContentType
    Switch $sExt
        Case 'jpg', 'jpe', 'jpeg'
            $sContentType = 'Content-Type: image/jpeg' ; ie 'Content-Type: image/pjpeg'
        Case 'gif'
            $sContentType = 'Content-Type: image/gif'
        Case 'bmp'
            $sContentType = 'Content-Type: image/bmp'
        Case 'png'
            $sContentType = 'Content-Type: image/png' ; ie Content-Type: image/x-png
        Case 'tif', 'tiff'
            $sContentType = 'Content-Type: image/tiff'
        Case Else
            Return SetError(2)
    EndSwitch
    Return $sContentType
EndFunc   ;==>_PicGetContentType

Func _PicReadData($sPicPath)
    If Not FileExists($sPicPath) Then Return SetError(-1)
    Local $hFile = FileOpen($sPicPath)
    If $hFile = -1 Then Return SetError(1)
    Local $sData = FileRead($hFile)
    If @error Then Return SetError(2)
    FileClose($hFile)
    Return $sData
EndFunc   ;==>_PicReadData

Func _GetFullNameByFullPath($sFullPath)
    Local $aFileName = StringSplit($sFullPath, '\')
    If Not @error Then Return $aFileName[$aFileName[0]]
    Return SetError(1)
EndFunc   ;==>_GetFullNameByFullPath

Func _GetExtByFullPath($sFullPath)
    Local $aFileName = StringSplit($sFullPath, '.')
    If Not @error Then Return $aFileName[$aFileName[0]]
    Return SetError(1)
EndFunc   ;==>_GetExtByFullPath
Link to post
Share on other sites

 

Nice work with TinyPicSharer!

I created a UDF from your script but I was wondering if it is possible to upload to a specific user account on ImageBam?

 

Thanks.  :)

$sBoundary need to be a global variable.

here is for be logged-in

#include 'WinHttp.au3'

$sNickName = '' 
$sPassword = ''
;~ $sHtmlPath = @DesktopDir & '\login.html'
$hOpen = _WinHttpOpen()
$hConnect = _WinHttpConnect ( $hOpen, 'www.imagebam.com' )
$sHtml = _WinHttpSimpleFormFill ( $hConnect, '/login', 'loginform2', 'name:nick', $sNickName, 'name:pw', $sPassword )
If @error Then ConsoleWrite ( '! @error : ' & @error & @Crlf )
ConsoleWrite ( '$sHtml : ' & $sHtml & @Crlf )
;~ FileWrite ( $sHtmlPath, $sHtml )
;~ ShellExecute ( $sHtmlPath )

; only close handles when upload is finished for not be logged out!


_WinHttpCloseHandle ( $hConnect )
_WinHttpCloseHandle ( $hOpen )

There is a "key" to recover in the html source return by this function, that we need for upload to the gallery

This key is also a part of the gallery Url : http://www.imagebam.com/gallery/dap34gcxxxxxxxxxxxx97e0xr

 

;~      <select name="gallery_existing" id="gallery_existing" class="input_sub" style="width:510px;">

;~                    <option value="x">SELECT GALLERY</option>
;~                    <option value='dap34gcxxxxxxxxxxxx97e0xr'>YourGalleryName</option>               </select>
;~            </div><!--/gallery_options_2-->

 

I'm working to the upload function but i meet some difficulties.

I'll see what I can do.

Edited by wakillon

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Link to post
Share on other sites

Now, once logged in, creation of gallery is possible without uploading a file.

#Region    ;************ Includes ************
#Include <ZLIB.au3>
#include<WinHttp.au3>
#EndRegion ;************ Includes ************

; login
$sNickName = ''
$sPassword = ''

$hOpen = _WinHttpOpen()
$hConnect = _WinHttpConnect ( $hOpen, 'www.imagebam.com' )
$sHtml = _WinHttpSimpleFormFill ( $hConnect, '/login', 'loginform2', 'name:nick', $sNickName, 'name:pw', $sPassword )

; create a gallery
$sGalleryName = 'MyGalleryName'
$sGalleryDescription = 'MyGalleryDescription'

$hRequest = _WinHttpOpenRequest ( $hConnect, 'POST', '/sys/ajax/gallery/create_json' )
_WinHttpAddRequestHeaders ( $hRequest, 'Accept-Encoding: gzip, deflate' )
_WinHttpAddRequestHeaders ( $hRequest, 'Content-Type: application/x-www-form-urlencoded' )
$sPost = 'content_type=0&thumb_size=100&thumb_aspect_ratio=resize&thumb_file_type=jpg&gallery_options=1&gallery_title=' & $sGalleryName & '&gallery_description=' & $sGalleryDescription & '&gallery_existing=x'
_WinHttpSendRequest ( $hRequest, $WINHTTP_NO_ADDITIONAL_HEADERS, $sPost, StringLen ( $sPost ) )
_WinHttpReceiveResponse ( $hRequest )
If _WinHttpQueryDataAvailable($hRequest) Then
    $sReceivedData = Binary ( '' )
    While 1
        $sReceivedData &= _WinHttpReadData ( $hRequest, 2 )
        If Not @extended Then ExitLoop
    WEnd
    $sReceivedData = BinaryToString ( _ZLIB_GZUncompress ( $sReceivedData ) )
EndIf

ConsoleWrite ( '$sReceivedData : ' & $sReceivedData & @Crlf ) ; {"status":"OK","GID":"xbc347j9gxxxxxxxxxxxxd9wndfq9ln"}

_WinHttpCloseHandle ( $hRequest )
_WinHttpCloseHandle ( $hConnect )
_WinHttpCloseHandle ( $hOpen )

In the received datas you will need to extract the "key" for get the gallery url as i mentioned in previous post.

:)

Edited by wakillon

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Link to post
Share on other sites

Now Gallery Deletion using the "key" for identify the gallery.

#Region    ;************ Includes ************
#Include <ZLIB.au3>
#include<WinHttp.au3>
#EndRegion ;************ Includes ************

; login
$sNickName = ''
$sPassword = ''

$hOpen = _WinHttpOpen()
$hConnect = _WinHttpConnect ( $hOpen, 'www.imagebam.com' )
$sHtml = _WinHttpSimpleFormFill ( $hConnect, '/login', 'loginform2', 'name:nick', $sNickName, 'name:pw', $sPassword )

; Delete a gallery

$hRequest = _WinHttpOpenRequest ( $hConnect, 'POST', '/sys/browse/delete_gallery/' )
_WinHttpAddRequestHeaders ( $hRequest, 'Accept-Encoding: gzip, deflate' )
_WinHttpAddRequestHeaders ( $hRequest, 'Content-Type: application/x-www-form-urlencoded' )
$sPost = 'GID=a8yayuxmxxxxxxxxxxbjekez4u518g'
_WinHttpSendRequest ( $hRequest, $WINHTTP_NO_ADDITIONAL_HEADERS, $sPost, StringLen ( $sPost ) )
_WinHttpReceiveResponse ( $hRequest )
If _WinHttpQueryDataAvailable($hRequest) Then
    $sReceivedData = Binary ( '' )
    While 1
        $sReceivedData &= _WinHttpReadData ( $hRequest, 2 )
        If Not @extended Then ExitLoop
    WEnd
    $sReceivedData = BinaryToString ( _ZLIB_GZUncompress ( $sReceivedData ) )
EndIf

ConsoleWrite ( '$sReceivedData : ' & $sReceivedData & @Crlf ) ; a8yayuxmxxxxxxxxxxbjekez4u518gOK
_WinHttpCloseHandle ( $hRequest )
_WinHttpCloseHandle ( $hConnect )
_WinHttpCloseHandle ( $hOpen )

If the deletion is done, it returns the submited key & 'OK'.

Edited by wakillon

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Link to post
Share on other sites

Now for Upload to Gallery

Func _HostImagebamSetDataToSendToGallery ( $sPicPath, $sGID, $GalleryName, $GalleryDescription='' )
    Local $sData = _PicReadData ( $sPicPath )
    If @error Then Return SetError ( 1 )
    Local $sImageName = _GetFullNameByFullPath ( $sPicPath )
    If @error Or $sImageName = '' Then Return SetError ( 2 )
    Local $sContentType = _PicGetContentType ( $sPicPath )
    If @error Then Return SetError ( 3 )
    Local $sCdfdn = 'Content-Disposition: form-data; name'
    Local $sCtaos = 'Content-Type: application/octet-stream'
    Local $sString = $sBoundary & @CRLF & _
        $sCdfdn & '="file[]"; filename="' & $sImageName & '"' & @CRLF & _
        $sContentType & @CRLF & @CRLF & $sData & @CRLF & $sBoundary & @CRLF
    For $i = 1 To 29
        $sString &= $sCdfdn & '="file[]"; filename=""' & @CRLF & _
            $sCtaos & @CRLF & @CRLF & @CRLF & $sBoundary & @CRLF
    Next
    $sString &= $sCdfdn & '="content_type"' & @CRLF & @CRLF & '0'                        & @CRLF & $sBoundary & @CRLF & _
        $sCdfdn & '="thumb_size"'           & @CRLF & @CRLF & '100'                      & @CRLF & $sBoundary & @CRLF & _
        $sCdfdn & '="thumb_aspect_ratio"'   & @CRLF & @CRLF & 'resize'                   & @CRLF & $sBoundary & @CRLF & _
        $sCdfdn & '="thumb_file_type"'      & @CRLF & @CRLF & 'jpg'                      & @CRLF & $sBoundary & @CRLF & _
        $sCdfdn & '="gallery_options"'      & @CRLF & @CRLF & '2'                        & @CRLF & $sBoundary & @CRLF & _ ; 2 : add
        $sCdfdn & '="gallery_title"'        & @CRLF & @CRLF & $GalleryName               & @CRLF & $sBoundary & @CRLF & _
        $sCdfdn & '="gallery_description"'  & @CRLF & @CRLF & $GalleryDescription        & @CRLF & $sBoundary & @CRLF & _
        $sCdfdn & '="gallery_existing"'     & @CRLF & @CRLF & $sGID & @CRLF & $sBoundary & '--'
    Return SetError ( 0, '', $sString )
EndFunc ;==> _HostImagebamSetDataToSendToGallery()


Func _HostImagebamUploadToGallery ( $sPicPath, $sGID, $GalleryName, $GalleryDescription='' )
    Local $hRequest, $sDataToSend, $sReceivedData, $iError, $sResponse, $sPostData, $sContentType
    $hRequest = _WinHttpOpenRequest ( $hConnect, 'POST', '/sys/upload/save', 'HTTP/1.1' )
    If @error Then
        SetError ( 3 )
    Else
        _WinHttpSetTimeouts ( $hRequest, 10000, 60000, 90000, 90000 )
        $sDataToSend = _HostImagebamSetDataToSendToGallery ( $sPicPath, $sGID, $GalleryName, $GalleryDescription )
        _WinHttpAddRequestHeaders ( $hRequest, 'Accept: application/x-ms-application, image/jpeg, application/xaml+xml, image/gif, image/pjpeg, application/x-ms-xbap, */*' )
        _WinHttpAddRequestHeaders ( $hRequest, 'Referer: http://www.imagebam.com/basic-upload' )
        _WinHttpAddRequestHeaders ( $hRequest, 'Host: www.imagebam.com' )
        _WinHttpAddRequestHeaders ( $hRequest, 'Accept-Encoding: gzip, deflate' )
        _WinHttpAddRequestHeaders ( $hRequest, 'Connection: Keep-Alive' )
        _WinHttpAddRequestHeaders ( $hRequest, 'Cache-Control: no-cache' )
        $sContentType = 'Content-Type: multipart/form-data; boundary=' & StringTrimLeft ( $sBoundary, 2 )
        _WinHttpSendRequest ( $hRequest, $sContentType, $WINHTTP_NO_REQUEST_DATA, StringLen ( $sDataToSend ) )
        If @error Then
            SetError ( 4 )
        Else
            _PicUploadProgress ( $hRequest, $sPicPath, $sDataToSend )
            If Not @error Then
                _WinHttpReceiveResponse ( $hRequest )
                If @error Then
                    SetError ( 5 )
                Else
                    If _WinHttpQueryDataAvailable ( $hRequest ) Then
                        $sReceivedData = Binary ( '' )
                        While 1
                            $sReceivedData &= _WinHttpReadData ( $hRequest, 2 )
                            If Not @extended Then
                                SetError ( 0 )
                                ExitLoop ;~
                            EndIf
                        WEnd
                        $sReceivedData = BinaryToString ( _ZLIB_GZUncompress ( $sReceivedData ) )
                        If StringInStr ( $sReceivedData, 'box_error' ) Then SetError ( 6 ) ; The thumbnail for the file pic.jpg could not be created.
                    Else
                        SetError ( 7 )
                    EndIf
                EndIf
            Else
                SetError ( 8 )
            EndIf
        EndIf
    EndIf
    $iError = @error
    If $hRequest Then _WinHttpCloseHandle ( $hRequest )
    If $hConnect Then _WinHttpCloseHandle ( $hConnect )
    If $hOpen Then _WinHttpCloseHandle ( $hOpen )
    Return SetError ( $iError, 0, $sReceivedData )
EndFunc ;==> _HostImagebamUploadToGallery()

$sGID is the key return after gallery creation.

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Link to post
Share on other sites

You are good with WinHTTP! Do you know a good place where I can learn more about WinHTTP?
 
To get the Gallery ID would be something like this?

Func _GetGalleryID($sReceivedData)
    Local $sPattern = '"GID":"(\w++)"}'
    If StringRegExp($sReceivedData,$sPattern,0) Then
        Return StringRegExp($sReceivedData,$sPattern,1)[0]
    Else
        Return ''
    EndIf
EndFunc

gallery creation, deletion and upload to gallery are working fine :)
 

#include <WinHTTP.au3>
#include <String.au3>
#include <Array.au3>
#include <zlib.au3>

$sBoundary = '--' & _GenerateBoundary(30)

; login
$sNickName = ''
$sPassword = ''

$sPicPath = ''
$GalleryName = ''

$hOpen = _WinHttpOpen()
$hConnect = _WinHttpConnect($hOpen, 'www.imagebam.com')
$sHtml = _WinHttpSimpleFormFill($hConnect, '/login', 'loginform2', 'name:nick', $sNickName, 'name:pw', $sPassword)

$sGID = _GalleryCreate($hConnect, $GalleryName)

Sleep(10000)

_HostImagebamUploadToGallery($sPicPath, $sGID, $GalleryName)

Sleep(10000)

_GalleryDelete($hConnect, $sGID)

_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)

#Region
Func _HostImagebamUploadToGallery($sPicPath, $sGID, $GalleryName, $GalleryDescription = '')
    Local $hRequest, $sDataToSend, $sReceivedData, $iError, $sResponse, $sPostData, $sContentType
    $hRequest = _WinHttpOpenRequest($hConnect, 'POST', '/sys/upload/save', 'HTTP/1.1')
    If @error Then
        SetError(3)
    Else
        _WinHttpSetTimeouts($hRequest, 10000, 60000, 90000, 90000)
        $sDataToSend = _HostImagebamSetDataToSendToGallery($sPicPath, $sGID, $GalleryName, $GalleryDescription)
        _WinHttpAddRequestHeaders($hRequest, 'Accept: application/x-ms-application, image/jpeg, application/xaml+xml, image/gif, image/pjpeg, application/x-ms-xbap, */*')
        _WinHttpAddRequestHeaders($hRequest, 'Referer: http://www.imagebam.com/basic-upload')
        _WinHttpAddRequestHeaders($hRequest, 'Host: www.imagebam.com')
        _WinHttpAddRequestHeaders($hRequest, 'Accept-Encoding: gzip, deflate')
        _WinHttpAddRequestHeaders($hRequest, 'Connection: Keep-Alive')
        _WinHttpAddRequestHeaders($hRequest, 'Cache-Control: no-cache')
        $sContentType = 'Content-Type: multipart/form-data; boundary=' & StringTrimLeft($sBoundary, 2)
        _WinHttpSendRequest($hRequest, $sContentType, $WINHTTP_NO_REQUEST_DATA, StringLen($sDataToSend))
        If @error Then
            SetError(4)
        Else
            _PicUploadProgress($hRequest, $sPicPath, $sDataToSend)
            If Not @error Then
                _WinHttpReceiveResponse($hRequest)
                If @error Then
                    SetError(5)
                Else
                    If _WinHttpQueryDataAvailable($hRequest) Then
                        $sReceivedData = Binary('')
                        While 1
                            $sReceivedData &= _WinHttpReadData($hRequest, 2)
                            If Not @extended Then
                                SetError(0)
                                ExitLoop ;~
                            EndIf
                        WEnd
                        $sReceivedData = BinaryToString( _ZLIB_GZUncompress($sReceivedData))
                        If StringInStr($sReceivedData, 'box_error') Then SetError(6) ; The thumbnail for the file pic.jpg could not be created.
                    Else
                        SetError(7)
                    EndIf
                EndIf
            Else
                SetError(8)
            EndIf
        EndIf
    EndIf
    $iError = @error
    If $hRequest Then _WinHttpCloseHandle($hRequest)
    Return SetError($iError, 0, $sReceivedData)
EndFunc   ;==>_HostImagebamUploadToGallery

Func _HostImagebamSetDataToSendToGallery($sPicPath, $sGID, $GalleryName, $GalleryDescription = '')
    Local $sData = _PicReadData($sPicPath)
    If @error Then Return SetError(1)
    Local $sImageName = _GetFullNameByFullPath($sPicPath)
    If @error Or $sImageName = '' Then Return SetError(2)
    Local $sContentType = _PicGetContentType($sPicPath)
    If @error Then Return SetError(3)
    Local $sCdfdn = 'Content-Disposition: form-data; name'
    Local $sCtaos = 'Content-Type: application/octet-stream'
    Local $sString = $sBoundary & @CRLF & _
            $sCdfdn & '="file[]"; filename="' & $sImageName & '"' & @CRLF & _
            $sContentType & @CRLF & @CRLF & $sData & @CRLF & $sBoundary & @CRLF
    For $i = 1 To 29
        $sString &= $sCdfdn & '="file[]"; filename=""' & @CRLF & _
                $sCtaos & @CRLF & @CRLF & @CRLF & $sBoundary & @CRLF
    Next
    $sString &= $sCdfdn & '="content_type"' & @CRLF & @CRLF & '0' & @CRLF & $sBoundary & @CRLF & _
            $sCdfdn & '="thumb_size"' & @CRLF & @CRLF & '100' & @CRLF & $sBoundary & @CRLF & _
            $sCdfdn & '="thumb_aspect_ratio"' & @CRLF & @CRLF & 'resize' & @CRLF & $sBoundary & @CRLF & _
            $sCdfdn & '="thumb_file_type"' & @CRLF & @CRLF & 'jpg' & @CRLF & $sBoundary & @CRLF & _
            $sCdfdn & '="gallery_options"' & @CRLF & @CRLF & '2' & @CRLF & $sBoundary & @CRLF & _ ; 2 : add
            $sCdfdn & '="gallery_title"' & @CRLF & @CRLF & $GalleryName & @CRLF & $sBoundary & @CRLF & _
            $sCdfdn & '="gallery_description"' & @CRLF & @CRLF & $GalleryDescription & @CRLF & $sBoundary & @CRLF & _
            $sCdfdn & '="gallery_existing"' & @CRLF & @CRLF & $sGID & @CRLF & $sBoundary & '--'
    Return SetError(0, '', $sString)
EndFunc   ;==>_HostImagebamSetDataToSendToGallery

Func _GalleryCreate($hConnect, $sGalleryName, $sGalleryDescription = '')
    $hRequest = _WinHttpOpenRequest($hConnect, 'POST', '/sys/ajax/gallery/create_json')
    _WinHttpAddRequestHeaders($hRequest, 'Accept-Encoding: gzip, deflate')
    _WinHttpAddRequestHeaders($hRequest, 'Content-Type: application/x-www-form-urlencoded')
    $sPost = 'content_type=0&thumb_size=100&thumb_aspect_ratio=resize&thumb_file_type=jpg&gallery_options=1&gallery_title=' & $sGalleryName & '&gallery_description=' & $sGalleryDescription & '&gallery_existing=x'
    _WinHttpSendRequest($hRequest, $WINHTTP_NO_ADDITIONAL_HEADERS, $sPost, StringLen($sPost))
    _WinHttpReceiveResponse($hRequest)
    If _WinHttpQueryDataAvailable($hRequest) Then
        $sReceivedData = Binary('')
        While 1
            $sReceivedData &= _WinHttpReadData($hRequest, 2)
            If Not @extended Then ExitLoop
        WEnd
        $sReceivedData = BinaryToString( _ZLIB_GZUncompress($sReceivedData))
    EndIf

    ConsoleWrite('$sReceivedData : ' & $sReceivedData & @CRLF) ; {"status":"OK","GID":"xbc347j9gxxxxxxxxxxxxd9wndfq9ln"}

    _WinHttpCloseHandle($hRequest)

    Return _GetGalleryID($sReceivedData)
EndFunc   ;==>_GalleryCreate

Func _GalleryDelete($hConnect, $sGID)
    $hRequest = _WinHttpOpenRequest($hConnect, 'POST', '/sys/browse/delete_gallery/')
    _WinHttpAddRequestHeaders($hRequest, 'Accept-Encoding: gzip, deflate')
    _WinHttpAddRequestHeaders($hRequest, 'Content-Type: application/x-www-form-urlencoded')
    $sPost = 'GID=' & $sGID
    _WinHttpSendRequest($hRequest, $WINHTTP_NO_ADDITIONAL_HEADERS, $sPost, StringLen($sPost))
    _WinHttpReceiveResponse($hRequest)
    If _WinHttpQueryDataAvailable($hRequest) Then
        $sReceivedData = Binary('')
        While 1
            $sReceivedData &= _WinHttpReadData($hRequest, 2)
            If Not @extended Then ExitLoop
        WEnd
        $sReceivedData = BinaryToString( _ZLIB_GZUncompress($sReceivedData))
    EndIf

    ConsoleWrite('$sReceivedData : ' & $sReceivedData & @CRLF) ; a8yayuxmxxxxxxxxxxbjekez4u518gOK
    _WinHttpCloseHandle($hRequest)
EndFunc   ;==>_GalleryDelete

Func _GetGalleryID($sReceivedData)
    Local $sPattern = '"GID":"(\w++)"}'
    If StringRegExp($sReceivedData, $sPattern, 0) Then
        Return StringRegExp($sReceivedData, $sPattern, 1)[0]
    Else
        Return ''
    EndIf
EndFunc   ;==>_GetGalleryID
#EndRegion

Func _PicUploadProgress($hRequest, $sPicPath, $sDataToSend)
    If Not FileExists($sPicPath) Then Return SetError(-1)
    Local $sDatas = StringToBinary($sDataToSend)
    Local $iNumberOfBytesToSend = 2048
    Local $Bin, $iPercent, $iStart = 1, $iExtended = 0
    While 1
        $Bin = BinaryMid($sDatas, $iStart, $iNumberOfBytesToSend)
        If BinaryLen($Bin) = 0 Then Return
        _WinHTTPWriteData($hRequest, $Bin, 1)
        If Not @error Then
            $iExtended += @extended
            $iPercent = Round(($iExtended) / (StringLen($sDataToSend)) * 100, 2)
            ConsoleWrite('-->-- [' & StringFormat('%03i', @ScriptLineNumber) & '][' & @HOUR & @MIN & @SEC & '] $iPercent : ' & $iPercent & @CRLF)
            If $iPercent > 97 Then $iPercent = 97
            $iStart += $iNumberOfBytesToSend
        Else
            $Bin = 0
            Return SetError(1)
        EndIf
    WEnd
EndFunc   ;==>_PicUploadProgress

Func _GenerateBoundary($iLen)
    Local $sString = ''
    Do
        Switch Random(1, 3, 1)
            Case 1
                $sString &= Chr(Random(48, 57, 1)) ; 0 to 9
            Case 2
                $sString &= Chr(Random(65, 90, 1)) ; A to Z
            Case 3
                $sString &= Chr(Random(97, 122, 1)) ; a to z
        EndSwitch
    Until StringLen($sString) = $iLen
    Return $sString
EndFunc   ;==>_GenerateBoundary

Func _PicGetContentType($sPicPath)
    If Not FileExists($sPicPath) Then Return SetError(-1)
    Local $sExt = _GetExtByFullPath($sPicPath)
    If @error Or $sExt = '' Then Return SetError(1)
    Local $sContentType
    Switch $sExt
        Case 'jpg', 'jpe', 'jpeg'
            $sContentType = 'Content-Type: image/jpeg' ; ie 'Content-Type: image/pjpeg'
        Case 'gif'
            $sContentType = 'Content-Type: image/gif'
        Case 'bmp'
            $sContentType = 'Content-Type: image/bmp'
        Case 'png'
            $sContentType = 'Content-Type: image/png' ; ie Content-Type: image/x-png
        Case 'tif', 'tiff'
            $sContentType = 'Content-Type: image/tiff'
        Case Else
            Return SetError(2)
    EndSwitch
    Return $sContentType
EndFunc   ;==>_PicGetContentType

Func _PicReadData($sPicPath)
    If Not FileExists($sPicPath) Then Return SetError(-1)
    Local $hFile = FileOpen($sPicPath)
    If $hFile = -1 Then Return SetError(1)
    Local $sData = FileRead($hFile)
    If @error Then Return SetError(2)
    FileClose($hFile)
    Return $sData
EndFunc   ;==>_PicReadData

Func _GetFullNameByFullPath($sFullPath)
    Local $aFileName = StringSplit($sFullPath, '\')
    If Not @error Then Return $aFileName[$aFileName[0]]
    Return SetError(1)
EndFunc   ;==>_GetFullNameByFullPath

Func _GetExtByFullPath($sFullPath)
    Local $aFileName = StringSplit($sFullPath, '.')
    If Not @error Then Return $aFileName[$aFileName[0]]
    Return SetError(1)
EndFunc   ;==>_GetExtByFullPath

Link to post
Share on other sites

I think this is the code to delete a picture: :D

#include <WinHTTP.au3>
#include <String.au3>
#include <Array.au3>
#include <zlib.au3>

$sBoundary = '--' & _GenerateBoundary(30)

; login
$sNickName = ''
$sPassword = ''

$sImageID = ''

$hOpen = _WinHttpOpen()
$hConnect = _WinHttpConnect($hOpen, 'www.imagebam.com')
$sHtml = _WinHttpSimpleFormFill($hConnect, '/login', 'loginform2', 'name:nick', $sNickName, 'name:pw', $sPassword)

$hRequest = _WinHttpOpenRequest($hConnect, 'POST', '/sys/browse/delete/', 'HTTP/1.1')
_WinHttpAddRequestHeaders($hRequest, 'Accept-Encoding: gzip, deflate')
_WinHttpAddRequestHeaders($hRequest, 'Content-Type: application/x-www-form-urlencoded')
$sPost = 'images=' & $sImageID
_WinHttpSendRequest($hRequest, $WINHTTP_NO_ADDITIONAL_HEADERS, $sPost, StringLen($sPost))
_WinHttpReceiveResponse($hRequest)
If _WinHttpQueryDataAvailable($hRequest) Then
    $sReceivedData = Binary('')
    While 1
        $sReceivedData &= _WinHttpReadData($hRequest, 2)
        If Not @extended Then ExitLoop
    WEnd
    $sReceivedData = BinaryToString( _ZLIB_GZUncompress($sReceivedData))
EndIf

ConsoleWrite('$sReceivedData : ' & $sReceivedData & @CRLF) ; a8yayuxmxxxxxxxxxxbjekez4u518gOK
_WinHttpCloseHandle($hRequest)
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)
Link to post
Share on other sites

You are good with WinHTTP! Do you know a good place where I can learn more about WinHTTP?

 

 

Thanks.

You can browse the trancexx WinHttp >Topic where you can find lot of examples,

and also the WinHttp.chm provided with WinHttp.au3 where there is some examples too !

And also here !  ;)

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Link to post
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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Colduction
      Hi again guys!, i had COVID-19 for twice and i couldn't check the forum since 3 or 4 months ago till now! i hope you will get better if you're fighting for beat COVID-19

      I have two question, first is about extracting all of the IP Address from an IP Ranges, for e.g: 192.168.1.1-192.255.255.255 (Start and End are variable and will be defined by the user) and for second one, i have a friend that he is Python programmer, he made a IP Parser that it can support large txt files (1TB) and it can parse all of them under 10min and it also supports low-end PCs that have 1 GB RAM!

      The list that his program parses are:
      #1765497 192.168.1.1 8082 #1765496 192.168.1.1 8084 #1965493 192.168.1.1 8089 #9565495 192.168.1.1 8086 #2565492 192.168.1.1 8081 and it converts very very fast to this:
      192.168.1.1:8082 192.168.1.1:8084 192.168.1.1:8089 192.168.1.1:8086 192.168.1.1:8081 I wonder how to do this via AutoIt, if you can help me in this way, i will be happy✌❤

      Thanks for your helps.

      FIRST_QUESTION_TEST.au3
    • By nooneclose
      I need to dynamically resize my 2d array while looping. 
      I know this code:
      ReDim $rArray[UBound($rArray) + 1] works for the rows, however, I also need to increase the columns. How would i go about increasing both rows and columns while looping? 
    • By jitendriya
      Hi every one .
      I want to read a pdf file and write into a excel using autoit , so how can i do this with out using third party server please tell me .
      Thank you..
    • By TheAutomator
      Is there a (simple) way to make your script using a picture-control to resize the gui?
      This would be useful for a transparant pop-up window with a custom made theme using picture controls:
      $Form = GUICreate('', 301, 173, 5, 5, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST)) GUICtrlCreatePic(@scriptdir & "\resize_win.bmp", 0, 73, 20, 51) ; some api call or code telling the os to use this picture as a resize border GUICtrlSetResizing(-1, $GUI_DOCKLEFT+$GUI_DOCKTOP+$GUI_DOCKBOTTOM+$GUI_DOCKWIDTH+$GUI_DOCKHEIGHT) GUISetState(@SW_SHOW) While True if GUIGetMsg() = $GUI_EVENT_CLOSE then Exit WEnd  
      EDIT: to make it more clear what i wanna do, if you go with the mouse arrow over the border of a re-sizable window the arrow changes to a "resize" arrow, you click and drag the border and then the window size adjusts to the mouse position until you release the mouse button.
      I want my picture control to be used the same way as the resize border to resize my window.
    • By Rex
      Some time ago I needed a way to uploade images to imgur, from one of my programs, and took a look at there API.
      Don't know if anyone can/would use it, but here is my code
       
      #AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7 ; #INDEX# ======================================================================================================================= ; Title .........: IMGUR Curl udf ; AutoIt Version : 1.0 ; Description ...: Uploads files to imgur using curl, and returns imgur url, deletion key, imgsize ect. in an array ; Author(s) .....: Rex ; =============================================================================================================================== #include-once #include <curl.au3> ; By Ward #include <JSON.au3> ; by Ward ; #FUNCTION# ==================================================================================================================== ; Name...........: _Imgur ; Description ...: Allows the user to uploade images to Imgur, or delete an already uploaded image using the images DeleteHash ; Syntax.........: _Imgur($AuthKey, True/False, $vData) ; Parameters ....: $AuthKey - API key from Imgur ; $bImg_Up - If true an image uploade is expected, if False a DeleteHas is expected ; $vData - The image to uploade, or the DeleteHash that was returned from Imgur at Image uploade ; Return values .: Success - An Array containing: ID, Datetime, type, animated, width, height, size, deletehash and url ; Failur - Sets @Error to 1 if no AuthKey is provided ; Failur - Sets @Error to 2 if $bImg_Up = True but no Image data is provided ; Failur - Sets @Error to 3 if $bImg_Up = True but $vData isn't Binary ; Failur - Sets @Error to 4 if $bImg_Up = False but no DeleteHash is provided ; Failur - Sets @Error to 5 if the API returns 400 -> Bad Request ; Failur - Sets @Error to 6 if the API returns 403 -> Permission Denied ; Failur - Sets @Error to 7 if the API returns 413 -> Data to large ; Failur - Sets @Error to 8 if the API returns 415 -> Unsupported data ; Failur - Sets @Error to 9 if Curl returns no Curl ; Failur - Sets @Error to 10 and returns Curl error msg if Curl fails ; Failur - Sets @Error to 11 If StringRegExp failed on the header (no array) ; Author ........: Rex ; Modified.......: ; Remarks .......: Needs Curl, Json And BinaryCall by Ward - Base64Encode By Ward and _EPOCH_Decrypt by Trancexx ; Is includede in the UDF is self ; Related .......: ; Link ..........: ; Example .......: $dFile = FileOpenDialog('Open', @ScriptDir, 'Image Files (*.jpg;*.jpeg;*.png;*.bmp;*.gif)', 1) ; Browse image ; $hData = FileOpen($dFile, 16) ; Open as binary ; $dData = FileRead($hData) ; Read the data ; FileClose($hData) ; Close the FileHandle ; $aData = _Imgur('APIKEY', True, $dData) ; Uploade the Image ; ; $aDelete = _Imgur('APIKEY', False, 'DELETEHASH') ; ; =============================================================================================================================== Func _Imgur($sAuthKey, $bImg_Up = True, $vData = '') ; Performe some error checking Select Case $sAuthKey = '' ; If no authkey is provided Return SetError(1, 0, -1) ; We set error to 1 Case $vData = '' And $bImg_Up = True ; If no image data is sendt Return SetError(2, 0, -1) ; We sent error to 2 Case $vData <> '' And $bImg_Up = True And IsBinary($vData) = 0 ; If $vData isn't binary Return SetError(3, 0, -1) ; We sent error to 3 Case $vData = '' And $bImg_Up = False ; If no deleta hash was send Return SetError(4, 0, -1) ; We sent error to 4 EndSelect Local $aResult[9] ; Return array Local $ProgressCallback = DllCallbackGetPtr(DllCallbackRegister("ShowProgress", "int:cdecl", "ptr;uint64;uint64;uint64;uint64")) Local $Curl = Curl_Easy_Init() If Not $Curl Then Return SetError(9, 0, -1) Local $sHtml = $Curl Local $sHeader = $Curl + 1 ; any number as identify Local $sList = Curl_Slist_Append(0, "User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:34.0) Gecko/20100101 Firefox/34.0") $sList = Curl_Slist_Append($sList, 'Referer: http://imgur.com/') $sList = Curl_Slist_Append($sList, 'Type: Base64') $sList = Curl_Slist_Append($sList, "Authorization: client-ID " & $sAuthKey) Curl_Easy_Setopt($Curl, $CURLOPT_HTTPHEADER, $sList) ; If $bImg_Up is true we uploads the image If $bImg_Up = True Then $dImage = _Base64Encode($vData) ; Convert the image to Base64 Curl_Easy_Setopt($Curl, $CURLOPT_URL, "https://api.imgur.com/3/upload/") ; If we wants to uploade an image Curl_Easy_Setopt($Curl, $CURLOPT_POST, 1) Curl_Easy_Setopt($Curl, $CURLOPT_COPYPOSTFIELDS, $dImage) Else ; If no img we expect a delete Curl_Easy_Setopt($Curl, $CURLOPT_URL, "https://api.imgur.com/3/image/" & $vData) ; If we wants to delete an image Curl_Easy_Setopt($Curl, $CURLOPT_CUSTOMREQUEST, 'DELETE') ; When we deletes an image EndIf ; Get header Curl_Easy_Setopt($Curl, $CURLOPT_HEADERFUNCTION, Curl_DataWriteCallback()) Curl_Easy_Setopt($Curl, $CURLOPT_HEADERDATA, $sHeader) Curl_Easy_Setopt($Curl, $CURLOPT_FOLLOWLOCATION, 1) ; Checks use this to see the respons from server, and get img url/delete hash ect. Curl_Easy_Setopt($Curl, $CURLOPT_WRITEFUNCTION, Curl_DataWriteCallback()) Curl_Easy_Setopt($Curl, $CURLOPT_WRITEDATA, $sHtml) Curl_Easy_Setopt($Curl, $CURLOPT_TIMEOUT, 30) Curl_Easy_Setopt($Curl, $CURLOPT_SSL_VERIFYPEER, 0) Curl_Easy_Setopt($Curl, $CURLOPT_NOPROGRESS, 0) Curl_Easy_Setopt($Curl, $CURLOPT_XFERINFOFUNCTION, $ProgressCallback) Local $Code = Curl_Easy_Perform($Curl) If $Code <> $CURLE_OK Then Return SetError(10, 0, Curl_Easy_StrError($Code)) EndIf ;ConsoleWrite(@CRLF & 'HEADER: ' & BinaryToString(Curl_Data_Get($sHeader)) & @CRLF) ;ConsoleWrite(@CRLF & 'HTML RAW: ' & BinaryToString(Curl_Data_Get($sHtml)) & @CRLF) ; Check what the header returns $aHeader = StringRegExp(BinaryToString(Curl_Data_Get($sHeader)), 'HTTP/1.1 (400|403|413|415|200)', 1) If IsArray($aHeader) Then Select Case $aHeader[0] = 400 ; If 403 then Permission Denied Return SetError(5, 0, -1) Case $aHeader[0] = 403 ; If 403 then Permission Denied Return SetError(6, 0, -1) Case $aHeader[0] = 413 ; If 413 then the data is to large Return SetError(7, 0, -1) Case $aHeader[0] = 415 ; If 415 then the data is unsupported Return SetError(8, 0, -1) Case $aHeader[0] = 200 ; If 200 uploade/delete was a sucess ; Decode the json returned from imgur Local $sJson = Json_Decode(BinaryToString(Curl_Data_Get($sHtml))) ; If deleting an image we only needs to return Sucess - IMGUR returns Sucess If $bImg_Up = False Then ReDim $aResult[1] ; Slim down the array $aResult[0] = 'Success' Return $aResult EndIf ; If an image was uploaded then we need to return some data to the user $aResult[0] = Json_Get($sJson, '["data"]["id"]') ; Imgur image id ; Date time the image was uploaded, it's returned in unix timestamp, so we converts it to regular time stamp $aResult[1] = _EPOCH_Decrypt(Json_Get($sJson, '["data"]["datetime"]')) ; Type of uploaded image $aResult[2] = Json_Get($sJson, '["data"]["type"]') ; Was the image animated $aResult[3] = Json_Get($sJson, '["data"]["animated"]') ; Width of the image $aResult[4] = Json_Get($sJson, '["data"]["width"]') ; Height of the image $aResult[5] = Json_Get($sJson, '["data"]["height"]') ; Size of the image $aResult[6] = Json_Get($sJson, '["data"]["size"]') ; Delete hash of the image $aResult[7] = Json_Get($sJson, '["data"]["deletehash"]') ; Image link $aResult[8] = Json_Get($sJson, '["data"]["link"]') Curl_Easy_Cleanup($Curl) Curl_Data_Cleanup($Curl) Curl_Slist_Free_All($sList) Return $aResult EndSelect Else ; If the Regexp failed Return SetError(11, 1, -1) EndIf EndFunc ;==>_Imgur Func ShowProgress($Ptr, $dltotal, $dlnow, $ultotal, $ulnow) ProgressSet(Int($ulnow / $ultotal * 100), '% Sendt = ' & Int($ulnow / $ultotal * 100)) Return 0 EndFunc ;==>ShowProgress ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name ..........: _EPOCH_Decrypt ; Description ...: Converts Epoch Time to human time ; Syntax ........: _EPOCH_Decrypt(TIMESTAMP) ; Return values .: Convertede timestamp ; Author ........: Trancexx ; Modified ......: ; Remarks .......: ; =============================================================================================================================== Func _EPOCH_Decrypt($iEpochTime) ; By trancexx forum thread: https://www.autoitscript.com/forum/topic/83667-epoch-time/ Local $iDayToAdd = Int($iEpochTime / 86400) Local $iTimeVal = Mod($iEpochTime, 86400) If $iTimeVal < 0 Then $iDayToAdd -= 1 $iTimeVal += 86400 EndIf Local $i_wFactor = Int((573371.75 + $iDayToAdd) / 36524.25) Local $i_xFactor = Int($i_wFactor / 4) Local $i_bFactor = 2442113 + $iDayToAdd + $i_wFactor - $i_xFactor Local $i_cFactor = Int(($i_bFactor - 122.1) / 365.25) Local $i_dFactor = Int(365.25 * $i_cFactor) Local $i_eFactor = Int(($i_bFactor - $i_dFactor) / 30.6001) Local $aDatePart[3] $aDatePart[2] = $i_bFactor - $i_dFactor - Int(30.6001 * $i_eFactor) $aDatePart[1] = $i_eFactor - 1 - 12 * ($i_eFactor - 2 > 11) $aDatePart[0] = $i_cFactor - 4716 + ($aDatePart[1] < 3) Local $aTimePart[3] $aTimePart[0] = Int($iTimeVal / 3600) $iTimeVal = Mod($iTimeVal, 3600) $aTimePart[1] = Int($iTimeVal / 60) $aTimePart[2] = Mod($iTimeVal, 60) Return StringFormat("%.2d/%.2d/%.2d %.2d:%.2d:%.2d", $aDatePart[0], $aDatePart[1], $aDatePart[2], $aTimePart[0], $aTimePart[1], $aTimePart[2]) EndFunc ;==>_EPOCH_Decrypt ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name ..........: _Base64Encode ; Description ...: Encodes data into Base64 ; Syntax ........: _Base64Encode(Data, Linebreak) ; Return values .: Base64 Encodede string ; Author ........: Ward ; Modified ......: ; Remarks .......: ; =============================================================================================================================== Func _Base64Encode($Data, $LineBreak = 76) ; By Ward Local $Opcode = '0x5589E5FF7514535657E8410000004142434445464748494A4B4C4D4E4F505152535455565758595A6162636465666768696A6B6C6D6E6F707172737' $Opcode &= '475767778797A303132333435363738392B2F005A8B5D088B7D108B4D0CE98F0000000FB633C1EE0201D68A06880731C083F901760C0FB6430125F0000000C1' $Opcode &= 'E8040FB63383E603C1E60409C601D68A0688470183F90176210FB6430225C0000000C1E8060FB6730183E60FC1E60209C601D68A06884702EB04C647023D83F' $Opcode &= '90276100FB6730283E63F01D68A06884703EB04C647033D8D5B038D7F0483E903836DFC04750C8B45148945FC66B80D0A66AB85C90F8F69FFFFFFC607005F5E' $Opcode &= '5BC9C21000' Local $CodeBuffer = DllStructCreate("byte[" & BinaryLen($Opcode) & "]") DllStructSetData($CodeBuffer, 1, $Opcode) $Data = Binary($Data) Local $Input = DllStructCreate("byte[" & BinaryLen($Data) & "]") DllStructSetData($Input, 1, $Data) $LineBreak = Floor($LineBreak / 4) * 4 Local $OputputSize = Ceiling(BinaryLen($Data) * 4 / 3) $OputputSize = $OputputSize + Ceiling($OputputSize / $LineBreak) * 2 + 4 Local $Ouput = DllStructCreate("char[" & $OputputSize & "]") DllCall("user32.dll", "none", "CallWindowProc", "ptr", DllStructGetPtr($CodeBuffer), _ "ptr", DllStructGetPtr($Input), _ "int", BinaryLen($Data), _ "ptr", DllStructGetPtr($Ouput), _ "uint", $LineBreak) Return DllStructGetData($Ouput, 1) EndFunc ;==>_Base64Encode I have added Wards curl, json and BinaryCall to the att. zip file.
       
      Cheers
      /Rex
      Includes.zip
×
×
  • Create New...