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 Jemboy
      Hi,
      For an internal project I want to write internal script to mail some special request to an external party.
      To make it a little bit universal I decided that the user should be able to write or edit the e-mail signature.
      Because I wanted to put a logo into the e-mail, I decided to use RichEdit.

      I I found the following code by  @UEZ and adapted it a little to save and load.
      When I start the script and edit the text only, I can save and load the signature.rtf.
      However the moment I resize one of the images (with the mouse), the script wil only save the edited image.
      Somehow resizing an image deletes the other content of the RichEdit object.
      Does anyone know a solution for me?
      P.s. you need to delete signature.rtf to reset the file.
      #include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <GuiRichEdit.au3> #include <WindowsConstants.au3> Example() Func Example() Local $hGui, $iMsg, $idBtnExit, $hRichEdit $hGui = GUICreate("Example (" & StringTrimRight(@ScriptName, StringLen(".exe")) & ")", 520, 550, -1, -1) $hRichEdit = _GUICtrlRichEdit_Create($hGui, "", 10, 10, 500, 490, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL)) $idBtnExit = GUICtrlCreateButton("Exit", 10, 510, 40, 30) $GoodRead = False If FileExists(@ScriptDir & "\signature.rtf") Then $ResSFF = _GUICtrlRichEdit_StreamFromFile($hRichEdit, @ScriptDir & "\signature.rtf") If $ResSFF=true then $GoodRead = True EndIf If $GoodRead=False Then _GUICtrlRichEdit_InsertText($hRichEdit, "Inserting image..." & @LF & @LF) _GUICtrlRichEdit_InsertText($hRichEdit, @LF & "JPG image scaled:" & @LF & @LF) _GUICtrlRichEdit_InsertBitmap($hRichEdit, "c:\Program Files (x86)\AutoIt3\Examples\GUI\mslogo.jpg", "\qc", "\picw6747\pich1058\picwgoal6690\pichgoal1860\") ;\qc = centered _GUICtrlRichEdit_InsertText($hRichEdit, @LF & @LF & "PNG image:" & @LF & @LF) _GUICtrlRichEdit_InsertBitmap($hRichEdit, "c:\Program Files (x86)\AutoIt3\Examples\GUI\Torus.png") _GUICtrlRichEdit_InsertText($hRichEdit, @LF & @LF & "Done.") EndIf GUISetState(@SW_SHOW) While True Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $idBtnExit _GUICtrlRichEdit_StreamToFile($hRichEdit, @ScriptDir & "\signature.rtf") _GUICtrlRichEdit_Destroy($hRichEdit) ; needed unless script crashes GUIDelete() Exit EndSwitch WEnd EndFunc ;==>Example Func _GUICtrlRichEdit_InsertBitmap($hWnd, $sFile, $sFormatFunctions = "\", $sBitmapFunctions = "\", $iBgColor = Default) ;coded by UEZ build 2016-02-16 If Not FileExists($sFile) Then Return SetError(0, 0, 1) If Not _WinAPI_IsClassName($hWnd, $__g_sRTFClassName) Then Return SetError(0, 0, 2) _GDIPlus_Startup() Local $hImage = _GDIPlus_ImageLoadFromFile($sFile) If @error Then _GDIPlus_Shutdown() Return SetError(0, 0, 3) EndIf Local Const $aDim = _GDIPlus_ImageGetDimension($hImage) Local Const $hBitmap = _GDIPlus_BitmapCreateFromScan0($aDim[0], $aDim[1]), $hGfx = _GDIPlus_ImageGetGraphicsContext($hBitmap) If $iBgColor = Default Then $iBgColor = 0xFF000000 + _WinAPI_SwitchColor(_GUICtrlRichEdit_GetBkColor($hWnd)) EndIf _GDIPlus_GraphicsClear($hGfx, $iBgColor) _GDIPlus_GraphicsDrawImageRect($hGfx, $hImage, 0, 0, $aDim[0], $aDim[1]) _GDIPlus_GraphicsDispose($hGfx) Local $binStream = _GDIPlus_StreamImage2BinaryString($hBitmap, "BMP") If @error Then _GDIPlus_ImageDispose($hImage) _GDIPlus_ImageDispose($hBitmap) _GDIPlus_Shutdown() Return SetError(0, 0, 4) EndIf Local $binBmp = StringMid($binStream, 31) Local Const $binRtf = "{\rtf1\viewkind4" & $sFormatFunctions & " {\pict{\*\picprop}" & $sBitmapFunctions & "dibitmap " & $binBmp & "}\par}" ;check out http://www.biblioscape.com/rtf15_spec.htm _GUICtrlRichEdit_AppendText($hWnd, $binRtf) $binStream = 0 $binBmp = 0 _GDIPlus_ImageDispose($hImage) _GDIPlus_ImageDispose($hBitmap) _GDIPlus_Shutdown() Return 1 EndFunc ;==>_GUICtrlRichEdit_InsertBitmap Func _GDIPlus_StreamImage2BinaryString($hBitmap, $sFormat = "JPG", $iQuality = 80, $bSave = False, $sFileName = @ScriptDir & "\Converted.jpg") ;coded by UEZ 2013 build 2014-01-25 (based on the code by Andreik) Local $sImgCLSID, $tGUID, $tParams, $tData Switch $sFormat Case "JPG" $sImgCLSID = _GDIPlus_EncodersGetCLSID($sFormat) $tGUID = _WinAPI_GUIDFromString($sImgCLSID) $tData = DllStructCreate("int Quality") DllStructSetData($tData, "Quality", $iQuality) ;quality 0-100 Local $pData = DllStructGetPtr($tData) $tParams = _GDIPlus_ParamInit(1) _GDIPlus_ParamAdd($tParams, $GDIP_EPGQUALITY, 1, $GDIP_EPTLONG, $pData) Case "PNG", "BMP", "GIF", "TIF" $sImgCLSID = _GDIPlus_EncodersGetCLSID($sFormat) $tGUID = _WinAPI_GUIDFromString($sImgCLSID) Case Else Return SetError(1, 0, 0) EndSwitch Local $hStream = _WinAPI_CreateStreamOnHGlobal() ;http://msdn.microsoft.com/en-us/library/ms864401.aspx If @error Then Return SetError(2, 0, 0) _GDIPlus_ImageSaveToStream($hBitmap, $hStream, DllStructGetPtr($tGUID), DllStructGetPtr($tParams)) If @error Then Return SetError(3, 0, 0) Local $hMemory = _WinAPI_GetHGlobalFromStream($hStream) ;http://msdn.microsoft.com/en-us/library/aa911736.aspx If @error Then Return SetError(4, 0, 0) Local $iMemSize = _MemGlobalSize($hMemory) If Not $iMemSize Then Return SetError(5, 0, 0) Local $pMem = _MemGlobalLock($hMemory) $tData = DllStructCreate("byte[" & $iMemSize & "]", $pMem) Local $bData = DllStructGetData($tData, 1) _WinAPI_ReleaseStream($hStream) ;http://msdn.microsoft.com/en-us/library/windows/desktop/ms221473(v=vs.85).aspx _MemGlobalFree($hMemory) If $bSave Then Local $hFile = FileOpen($sFileName, 18) If @error Then Return SetError(6, 0, $bData) FileWrite($hFile, $bData) FileClose($hFile) EndIf Return $bData EndFunc ;==>_GDIPlus_StreamImage2BinaryString  
       
    • By RAMzor
      Hi everyone,
      I have this string:
      "main_lot      0x111” & @CRLF & “main_version          0xABC” & @CRLF & “main_number 0xDEAD123” & @CRLF & “main_version          0x333"
      And I'm trying to extract one specific hexadecimal number, actually main_version from this string by using StringRegExp:
      How to get 'ABC' from it?
      I'm not sure if the original string uses @CRLF, @CR or @LF as a line breaks (received from linux over ssh plink.exe) I have tried this code but it doesn't work 
      #include <Array.au3> $sLog = "main_lot 0x111” & @CRLF & “main_version 0xABC” & @CRLF & “main_number 0xDEAD123” & @CRLF & “main_version 0x333" $aVer = StringRegExp($sLog, "main_version\h*(.+)(?:0[xX][[:xdigit:]])", 3) _ArrayDisplay($aVer)  
       
    • By Aapjuh
      Hi,
      I am having a problem properly saving the Width of a resizable Gui.
      When a user resizes the Gui it gets saved in an ini when the Gui closes to then restore the new Width upon reopening the app.
      with GUICreate("myGui",300,200,Default,Default,$WS_SIZEBOX)
      WinGetPos($hGUI) returns 314, and WinGetClientSize($hGUI) returns 298
      when its then saved in the ini the gui keeps expanding or shrinking every time its opened by +14 or -2
      I figure it has to do with borders etc, but i also guess borders depend on the window theme and whatnot or is user specific, so i can't just do $GuiWidth = $GetGuiWidth[arr] -14 or +2 right?

      is there a proper way of doing this?
      Thanks in advance,
      Aapjuh
    • 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? 
×
×
  • Create New...