rejetto forum
Software => HFS ~ HTTP File Server => Topic started by: Daniel Z on August 29, 2007, 12:40:11 PM
-
i want to develop a client software, upload a file to HFS,
someone can give me a sample code for that. Thanks a lot.
-
find an HTTP lib for your programming language first.
-
hi, rejetto, thanks for your reply. i used WinINet.
this is my code, but dosen't work, Plz help me again, thank you.
ALocalFile:= 'D:\upload\111.txt';
ARemoteServer:= '127.0.0.1';
ARemoteFile:= '/101_111.txt';
HttpNet := InternetOpen(PChar(ARemoteServer), INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
HttpConnect := InternetConnect(HttpNet, PChar(ARemoteServer), 0, nil, nil, INTERNET_SERVICE_HTTP, 0, 0);
HttpRequest := HttpOpenRequest(HttpConnect, 'PUT', PChar(ARemoteFile), nil, nil, nil, 0, 0);
hFile := CreateFile(PChar(ALocalFile), GENERIC_READ, FILE_SHARE_READ, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
FillChar(BufferIn, SizeOf(BufferIn), 0);
BufferIn.dwStructSize := SizeOf(BufferIn);
BufferIn.dwBufferLength := cBuffsize;
BufferIn.dwBufferTotal := GetFileSize(hFile, nil);
HttpSendRequestEx(HttpRequest, @BufferIn, nil, HSR_INITIATE, 0);
ReadInF := 0;
repeat
SetLength(pBuffer, cBuffsize);
ReadFile(hFile, Pointer(pBuffer)^, cBuffsize, Count, nil);
ReadInF := ReadInF + Count;
InternetWriteFile(httpRequest, Pointer(pBuffer), Count, oBytesWritten);
until ReadInF = BufferIn.dwBufferTotal;
HttpEndRequest(HttpRequest, nil, 0, 0);
InternetCloseHandle(HttpRequest);
InternetCloseHandle(HttpConnect);
InternetCloseHandle(HttpNet);
-
i don't know the lib you are using, but you don't have to use the PUT method.
use the POST method towards the ~upload page.
-
thank you again!
and i follow you to used a IdHTTP send a file to server.
var
res : String;
mps : TIdMultiPartFormDataStream;
begin
try
mps := TIdMultiPartFormDataStream.Create;
mps.AddFile('File1','D:\222.txt','');
res:=idhttp1.Post('http://192.168.1.100/test/~upload', mps);
finally
mps.Free;
end;
the HFS is already reciving that file, but there is an error :
Upload failed, Folder not found: 222.txt
how to fix that, thanks!
-
are you sure the test folder does exist?
-
yes, I am sure
and the test folder is a real folder.
and everyone can upload file to the test folder, i already test used web, it's ok.
-
sorry, i was wrong.
you have to post to the folder, not the ~upload page.
anyway, while testing your procedure to find what was wrong, i found some bugs in the upload handling.
if we are lucky this may fix an old terrific bug (http://www.rejetto.com/forum/?topic=4606).
so, use the last beta for your tests.
-
i tried it used the latest beta version 128#.
but there is a new problem.
the connection cannot be auto disconnected when the transfer finished.
It will be disconnected until the time out.
The file can be uploaded to server successfully but the size is wrong. Destination file size more than source file about 2-3bit.
-
there's no need to disconnect,
but you can break the connection if you really want to.
make a test so that i can see the file size problem on my computer.
-
hi, there is the test.
-
fixed in next build
-
thanks a lot!
waitting for next version.
and i tried the #130 it's work well. :)