Gimerly Posted May 27, 2014 Share Posted May 27, 2014 Hello all again. I have been doing research for the past 2 weeks into uploading a file and I just don't understand how to do it. I am using WinHttp and the idea is to click the upload button have the user select a file they wish to upload in a dialog menu and then upload it. I really dont understand how to do it and need some help. If anyone can help I would be very thankful Link to comment Share on other sites More sharing options...
guinness Posted May 27, 2014 Share Posted May 27, 2014 What is the website? What code do you have? Have you looked at the well documented WinHttp documentation? UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
JohnOne Posted May 27, 2014 Share Posted May 27, 2014 Two weeks you say! You must have some code to show then. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Gimerly Posted May 27, 2014 Author Share Posted May 27, 2014 (edited) Yep I do. Just got it working in fact (I know what you're thinking this kid is full of shit.) But as it turns out I wasn't putting a time stamp in my url (which dropbox needs) here is the code if anyone else is looking for a way to send files to dropbox (Also sorry for wasting time JohnOne) expandcollapse popupfunc upload() Local $sDrive = "", $sDir = "", $sFilename = "", $sExtension = "" local $time=currenttime() local $Random = Random(0,32767,1) $File = fileopendialog("Downloads", @scriptdir, "All (*.*)" ) local $array = _PathSplit($File,$sDrive, $sDir, $sFilename, $sExtension) Local $i = UBound($array) - 1 local $sFile = fileopen($File) Local $sUrl = ("https://api-content.dropbox.com/1/files_put/dropbox"&"/"&$array[$i-1]&$array[$i]&'?oauth_consumer_key='&$App_Key&"&oauth_token="&$Oauth_access_token&"&oauth_signature="&$App_secret&"%26"&$Oauth_access_token_secret&"&oauth_timestamp="&$time&"&oauth_nonce="&$RANDOM) message($sUrl) Local $obj = ObjCreate("WinHttp.WinHttpRequest.5.1") ;message("here") $obj.Open("PUT", $sURL, False) If @error Then message("Couldnt open request") else message("request opened") $obj.SetRequestHeader("Content-Type", " application/x-www-form-urlencoded"); $obj.SetRequestHeader("Content-Length", StringLen($File)) if _FindNetwork() = "xavier" Then $obj.SetProxy(2, "number") endif $obj.Send($sFile) $oReceived = $obj.ResponseText $oStatusCode = $obj.Status If $obj.Status <> $HTTP_STATUS_OK Then local $FindError = FindError($oStatusCode) message($FindError) else endif endif endfunc Edited May 27, 2014 by Gimerly Link to comment Share on other sites More sharing options...
guinness Posted May 27, 2014 Share Posted May 27, 2014 Why not look at trancexx's UDF called WinHttp? UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
Gimerly Posted May 27, 2014 Author Share Posted May 27, 2014 (edited) I got it working, thanks for the reply. I just posted that so that if other people where having trouble uploading to dropbox they use that code as a template for their script. And if you look at the code I am using WinHttp() Edited May 27, 2014 by Gimerly Link to comment Share on other sites More sharing options...
guinness Posted May 27, 2014 Share Posted May 27, 2014 WinHttp >> '?do=embed' frameborder='0' data-embedContent>> UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
Gimerly Posted May 28, 2014 Author Share Posted May 28, 2014 Actually there is a problem with the code I just discovered. While it does upload "a" file it doesn't actually upload the file contents. for a text file it uploads the number of words and for an image it is corrupt. Can someone help me ? expandcollapse popupfunc upload() trayseticon("C:\Program Files\AutoIt3\Icons\cute panda.ico", -1) Local $sDrive = "", $sDir = "", $sFilename = "", $sExtension = "" local $time=currenttime() local $Random = Random(0,32767,1) $File = fileopendialog("Pick something to upload", @desktopdir, "All (*.*)" ) local $array = _PathSplit($File,$sDrive, $sDir, $sFilename, $sExtension) ; split the directory into drive, dir, filename and extension Local $i = UBound($array) - 1 local $sFile = fileopen($File,0) Local $sUrl = ("https://api-content.dropbox.com/1/files_put/dropbox"&"/"&$array[$i-1]&$array[$i]&'?oauth_consumer_key='&$App_Key&"&oauth_token="&$Oauth_access_token&"&oauth_signature="&$App_secret&"%26"&$Oauth_access_token_secret&"&oauth_timestamp="&$time&"&oauth_nonce="&$RANDOM) ;$array[$i-1] is the file name of the file the user wants to upload and $array[$i] is the extension Local $obj = ObjCreate("WinHttp.WinHttpRequest.5.1") ;message("here") $obj.Open("PUT", $sURL, False) If @error Then _Toast_Set(2) _Toast_Show(@scriptdir & "/puffypanda.exe", "Error", "Unable to upload" & " " &$array[$i-1] & $array[$i], 2, true, true) _Toast_Hide(10) else ; message("request opened") $obj.SetRequestHeader("Content-Type", " application/x-www-form-urlencoded"); dropbox needs the url to be encoded for security reasons $obj.SetRequestHeader("Content-Length", StringLen($File)) if _FindNetwork() = "xavier" Then $obj.SetProxy(2, "proxy.school:3128") $obj.Send($sFile) ; send the file to uploaded $oReceived = $obj.ResponseText $oStatusCode = $obj.Status If $obj.Status <> $HTTP_STATUS_OK Then local $FindError = FindError($oStatusCode) message($FindError) _Toast_Set(2) _Toast_Show(@scriptdir & "/puffypanda.exe", "Error", "Unable to upload" & " " &$array[$i-1] & $array[$i], 2, true, true) _Toast_Hide(10) trayseticon("C:\Program Files\AutoIt3\Icons\panda.ico", -1) else _log("uploaded" & " " & $array[$i-1] & $array[$i]) _Toast_Set(2) _Toast_Show(@scriptdir & "/puffypanda.exe", "Success", "You successfully uploaded" & " " & $array[$i-1] & $array[$i], 2, true, true) _Toast_Hide(10) trayseticon("C:\Program Files\AutoIt3\Icons\panda.ico", -1) endif endif endif FileClose($File) endfunc Link to comment Share on other sites More sharing options...
Gimerly Posted May 29, 2014 Author Share Posted May 29, 2014 (edited) Never mind Just figured it out. Problem was me sending the size and reading of the file. For anyone wanting to upload to a dropbox account you can use this code: expandcollapse popupfunc upload() trayseticon("C:\Program Files\AutoIt3\Icons\cute panda.ico", -1) Local $sDrive = "", $sDir = "", $sFilename = "", $sExtension = "" local $time=currenttime() local $Random = Random(0,32767,1) local $File = fileopendialog("Pick something to upload", @desktopdir, "All (*.*)|Text files (*.txt)" ) ;message($File) local $array = _PathSplit($File,$sDrive, $sDir, $sFilename, $sExtension) ; get the file name and extension Local $i = UBound($array) - 1 local $sFile = fileopen($File,16) Local $data = fileread($sFile) local $size = @extended FileClose($File) Local $sUrl = ("https://api-content.dropbox.com/1/files_put/dropbox"&"/"&$array[$i-1]&$array[$i]&'?oauth_consumer_key='&$App_Key&"&oauth_token="&$Oauth_access_token&"&oauth_signature_method=PLAINTEXT&oauth_signature="&$App_secret&"%26"&$Oauth_access_token_secret&"&oauth_timestamp="&$time&"&oauth_nonce="&$RANDOM) ;$array[$i-1] is the file name of the file the user wants to upload and $array[$i] is the extension Local $obj = ObjCreate("WinHttp.WinHttpRequest.5.1") ;message("here") $obj.Open("PUT", $sURL, False) If @error Then _Toast_Set(2) _Toast_Show(@scriptdir & "/puffypanda.exe", "Error", "unable to upload" & " " &$array[$i-1] & $array[$i], 2, true, true) _Toast_Hide(10) else ; message("request opened") $obj.SetRequestHeader("User-Agent", "User-Agent=Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0") ;$obj.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded") $obj.SetRequestHeader("Content-Length", $size) if _FindNetwork() = "xavier" Then $obj.SetProxy(2, "number") endif ; message($sFile) $obj.Send($data) ; send the file to uploaded $oReceived = $obj.ResponseText $oStatusCode = $obj.Status If $obj.Status <> $HTTP_STATUS_OK Then local $FindError = FindError($oStatusCode) message($oReceived) msgbox(0 , "Error", "unable to uploaded" & " " & $array[$i-1] & $array[$i]) trayseticon("C:\Program Files\AutoIt3\Icons\panda.ico", -1) else msgbox(0 , "success", "uploaded" & " " & $array[$i-1] & $array[$i]) trayseticon("C:\Program Files\AutoIt3\Icons\panda.ico", -1) endif endif endfunc Edited May 31, 2014 by Gimerly Link to comment Share on other sites More sharing options...
Deye Posted July 1, 2016 Share Posted July 1, 2016 (edited) I'm replying here since I cannot find any other topics that can help demonstrate more on the Dropbox authenticator: I tried Gimerly's Dropbox authenticator to get the $Oauth_access_token that returns in this syntax "oauth_token_secret=xxxxxxxx&oauth_token=xxxxxxxx&uid=xxxxxxxx" using it with the upload() function from the post above, doesn't seem to work for me. maybe someone who tried this or is more experienced with this code can help shed a light. TIA EDIT: this page for Node.js seems to have covered most of the needed procedureshttps://www.built.io/blog/2014/08/file-uploading-in-dropbox-using-node-js/ Edited July 1, 2016 by Deye Link to comment Share on other sites More sharing options...
Sarah2016 Posted December 7, 2016 Share Posted December 7, 2016 (edited) if _FindNetwork() = "xavier" Then $obj.SetProxy(2, "number") endif I get error for the above code. Any Help? & what does this code exactly do? Edited December 7, 2016 by Sarah2016 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now