Registriert seit: 2. Jun 2004
Ort: Cremlingen
90 Beiträge
Delphi 10.2 Tokyo Professional
|
AW: Datasnap File Upload
4. Dez 2011, 02:31
Das ist bisher der Server:
Delphi-Quellcode:
procedure TServerMethods.UploadFile(str: TStream; Store, FileName: string);
var
aFileStream: TFileStream;
BytesReadCount: Integer;
Buffer: array [1 .. 16 * 1024] of Byte;
begin
if not DirectoryExists(ExtractFilePath(ParamStr(0)) + 'Files\' + Store) then
begin
MkDir(ExtractFilePath(ParamStr(0)) + 'Files\' + Store);
end;
aFileStream := TFileStream.Create(ExtractFilePath(ParamStr(0)) + 'Files\' + Store + '\' + FileName, fmCreate);
try
repeat
BytesReadCount := str.Read(Buffer, BufferSize);
aFileStream.Write(Buffer, BytesReadCount);
until (BytesReadCount < SizeOf(Buffer));
str.Position := 0;
finally
aFileStream.Free;
end;
end;
Und der Client:
Delphi-Quellcode:
procedure TfrmMain.btnSendClick(Sender: TObject);
var
aFileStream: TFileStream;
i: Integer;
begin
if lbFiles.Count > 0 then
begin
try
for i := 0 to lbFiles.Items.Count - 1 do
begin
aFileStream := TFileStream.Create(lbFiles.Items[i], fmOpenRead);
try
begin
aClient.UploadFile(aFileStream, Store, ExtractFileName(lbFiles.Items[i]));
lbFiles.Clear;
end
except
begin
ShowMessage('Übertragung fehlerhaft!');
end;
end;
end;
finally
aFileStream.Free;
btnSend.Enabled := False;
end;
end
else
begin
Konsole.TextHinweis('Keine Dateien zum Senden vorhanden.');
end;
end;
Matthias Wer nichts wagt der nichts verliert.
|
|
Zitat
|