autoituser123 Posted November 22, 2009 Share Posted November 22, 2009 Hello Guru I'm trying to upload binary Data to a sample test web site. I do FileRead($file_to_upload,16) and post uploading using WinHTTP routine. The file is uploaded but corrupted. The fileRead function skips Null character and makes the file corrupted. Any idea? Thank you so much. Link to comment Share on other sites More sharing options...
BrettF Posted November 22, 2009 Share Posted November 22, 2009 Welcome to the forum. My crystal ball is cloudy. Please post your code or a reproducer of your problem so we may assist you. We cannot help you without that. Cheers Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
IchBistTod Posted November 22, 2009 Share Posted November 22, 2009 are you making sure to url encode the data before transmitting it? if so you may want to try converting it to hex before uploading so that everything in the data is then represented by a number,then using php to turn it back into binary on the server side. BTW, fileread is not skipping anything thats simply not possible, the issue is in your handling of the data. hope this helps [center][/center][center]=][u][/u][/center][center][/center] Link to comment Share on other sites More sharing options...
suthers Posted November 22, 2009 Share Posted November 22, 2009 Code sample definately required. A flag of 16 for binary usage is used with FileOpen(), not FileRead(). Using it with FileRead() will only read the first 16 characters. Link to comment Share on other sites More sharing options...
autoituser123 Posted November 24, 2009 Author Share Posted November 24, 2009 (edited) Hello Thanks for all replies. @IchBistTod, I'm not clear about how to convert it to hex before uploading so that everything in the data is then represented by a number,then using php to turn it back into binary on the server side. When I use FileRead, it's something like 0x332330x343333 ... For PHP, I find only number conversion functions like bin2hex, hexdec not data format conversion. Here's my code: expandcollapse popup#include "WinHTTP.au3" #include <IE.au3> $LocalIP = "localhost" $PostURL = "/upload_php.php" $hw_open = _WinHttpOpen() $hw_connect = _WinHttpConnect($hw_open, $LocalIP) $h_openRequest = _WinHttpOpenRequest($hw_connect, "POST", $PostURL) $upfile = "test.jpg"; $upsize = FileGetSize($upfile) $file = FileOpen($upfile , 16) ; Check if file opened for reading OK If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf ; Read in lines of text until the EOF is reached $line = "" While 1 $line &= FileReadLine($file) If @error = -1 Then ExitLoop Wend FileClose($file) $upcontent = $line $data = "-----------------------------41184676334" & @CRLF & 'Content-Disposition: form-data; name="userfile"; filename="' & $upfile & '"' & @CRLF & 'Content-Type: application/octet-stream' & @CRLF & @CRLF & $upcontent & @CRLF & '-----------------------------41184676334--' & @CRLF _WinHttpAddRequestHeaders($h_openRequest,"Content-Type: multipart/form-data; boundary=---------------------------41184676334") _WinHttpSendRequest($h_openRequest,$WINHTTP_NO_ADDITIONAL_HEADERS, $WINHTTP_NO_REQUEST_DATA, StringLen($data), 0) _WinHttpWriteData($h_openRequest, $data) _WinHttpReceiveResponse($h_openRequest) $oIE=_IECreate () _IEDocWriteHTML ( $oIE, _WinHttpReadData($h_openRequest)) _WinHttpCloseHandle($h_openRequest) _WinHttpCloseHandle($hw_connect) _WinHttpCloseHandle($hw_open) Edited November 24, 2009 by autoituser123 Link to comment Share on other sites More sharing options...
autoituser123 Posted November 28, 2009 Author Share Posted November 28, 2009 Does anyone care to find solutions for my code? Link to comment Share on other sites More sharing options...
ProgAndy Posted November 28, 2009 Share Posted November 28, 2009 Try this: http://www.autoitscript.com/forum/index.php?showtopic=84133&view=findpost&p=610967 *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes Link to comment Share on other sites More sharing options...
autoituser123 Posted November 29, 2009 Author Share Posted November 29, 2009 Try this: #610967 When I run your http://www.autoitscript.com/forum/index.php?app=core&module=attach§ion=attach&attach_id=23306 I got post_upload2.au3 (216) : ==> Incorrect number of parameters in function call.: Local $szExt = StringLower(StringRegExpReplace(".*(?:\.([^.\\/]*))?\Z","$1")) Local $szExt = StringLower(^ ERROR Link to comment Share on other sites More sharing options...
ProgAndy Posted November 29, 2009 Share Posted November 29, 2009 Oops, replaceLocal $szExt = StringLower(StringRegExpReplace(,".*(?:\.([^.\\/]*))?\Z","$1"))with Local $szExt = StringLower(StringRegExpReplace( $path ,".*(?:\.([^.\\/]*))?\Z","$1")) *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes 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