Gimerly

Uploading a file to http server

11 posts in this topic

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 

Share this post


Link to post
Share on other sites



What is the website? What code do you have? Have you looked at the well documented WinHttp documentation?


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

#4 ·  Posted (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) 

func 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 by Gimerly

Share this post


Link to post
Share on other sites

Why not look at trancexx's UDF called WinHttp?


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

#6 ·  Posted (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 by Gimerly

Share this post


Link to post
Share on other sites

_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

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 ?

func 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

Share this post


Link to post
Share on other sites

#9 ·  Posted (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:

func 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 by Gimerly

Share this post


Link to post
Share on other sites

#10 ·  Posted (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 procedures
https://www.built.io/blog/2014/08/file-uploading-in-dropbox-using-node-js/
 

Edited by Deye

Share this post


Link to post
Share on other sites

#11 ·  Posted (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 by Sarah2016

Share this post


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