큰 파일 업로드/다운로드
12840 단어 demo
첨부: 아래 코드, 전재는 출처를 밝혀 주십시오
::code
서비스 포트:
function TServerMethods1.DownLoadFile(AfileName: string): TStream;
const
SaveFolder = 'FSimage\';
defaultName = 'Default.png'; //
//
var
ALLpath: string;
begin
ALLpath := LocalPath + SaveFolder + AfileName;
if not FileExists(ALLpath) then
ALLpath := LocalPath + SaveFolder + defaultName;
Result := TFileStream.Create(ALLpath, fmOpenRead);
Result.Position := 0;
//
end;
function TServerMethods1.PutFile(AfileName: string; Stream: TStream): Boolean;
const
BufSize = $F000;
SaveFolder = 'FSimage\';
var
Buffer: TBytes;
ReadCount: Integer;
FS: TFileStream;
begin
if not DirectoryExists(LocalPath + SaveFolder) then
CreateDir(LocalPath + SaveFolder);
FS := TFileStream.Create(LocalPath + SaveFolder + AfileName, FmCreate);
try
if Stream.Size = -1 then //
begin
SetLength(Buffer, BufSize);
repeat
ReadCount := Stream.Read(Buffer[0], BufSize);
if ReadCount > 0 then
FS.WriteBuffer(Buffer[0], ReadCount);
if ReadCount < BufSize then
break;
until ReadCount < BufSize;
end
else //
FS.CopyFrom(Stream, 0);
Result := True;
finally
FS.Free;
end;
end;
클라이언트:
procedure TForm1.Button1Click(Sender: TObject);
var
cs: TServerMethods1Client;
memoryStream: TMemoryStream;
begin
cs := TServerMethods1Client.Create(self.SQLConnection1.DBXConnection);
try
memoryStream := TMemoryStream.Create;
try
// Image1.Picture.Graphic.SaveToStream(memoryStream);
SaveAs(Image1.Picture.Graphic, memoryStream, gptPNG);
memoryStream.Position := 0;
// memoryStream.Seek(0, TSeekOrigin.soBeginning);
if cs.PutFile('1.png', memoryStream) then
ShowMessage(' ')
else
ShowMessage(' ');
finally
if memoryStream <> nil then
memoryStream := nil;
end;
finally
cs.free;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
DownLoadfs(Image1.Picture,'1.png')
end;
procedure TForm1.DownLoadfs(Ggs:TPicture;fsName: string);
const
BufSize = $F000;
var
Stream, FS: TStream;
cs: TServerMethods1Client;
syn: TSynPicture;
Buffer: TBytes;
ReadCount: Integer;
begin
cs := TServerMethods1Client.Create(self.SQLConnection1.DBXConnection);
try
Stream := cs.DownLoadFile(fsName);
FS := TMemoryStream.Create;
try
if Stream.Size = -1 then //
begin
SetLength(Buffer, BufSize);
repeat
ReadCount := Stream.Read(Buffer[0], BufSize);
if ReadCount > 0 then
FS.WriteBuffer(Buffer[0], ReadCount);
if ReadCount < BufSize then
break;
until ReadCount < BufSize;
end
else //
FS.CopyFrom(Stream, 0);
syn := TSynPicture.Create;
try
syn.LoadFromStream(FS);
Ggs.Assign(syn);
finally
syn.free;
end;
finally
FS.free;
end;
finally
cs.free;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
self.SQLConnection1.Connected := True;
gdip := TGDIPlusFull.Create('gdiplus.dll');
end;
procedure TForm1.Image1DblClick(Sender: TObject);
var
syn: TSynPicture;
begin
if self.OpenDialog1.Execute then
begin
if self.OpenDialog1.FileName = '' then
Exit
else
begin
syn := TSynPicture.Create;
try
syn.LoadFromFile(self.OpenDialog1.FileName);
self.Image1.Picture.Assign(syn);
finally
syn.free;
end;
end;
end;
end;
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Axios API 호출에 대한 간단한 설명우리는 페이지'사용자 페이지 1'과'사용자 페이지 2'에 두 개의 단추를 가지고 있다. 사용자가 사용자 페이지 1을 클릭하면 외부 API에서 페이지 1의 사용자 결과를 가져와 표시합니다. 그렇지 않으면 사용자 페이지...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.