Мне тоже средством апликухи негодился, а то тогда юзеру
должен бить доступ к ним, значить он их может удолить, а для нас
там серёзные докозательство о том кто что распечатывал (у нас копии
распечатки так хранятся), а на сервере никто и незнает где что хранится
и недобратся ...
Код:
function WriteFileToBlob(FileName: PChar; Blob: PBlob): PBlob; Cdecl;
export;
Var bytes_read, bufsize :Ushort;
total_bytes_write :Long;
buff :Pointer;
Fs :TFileStream;
begin
Result := Blob;
If (Not Assigned(Blob)) Or (Not Assigned(Blob^.BlobHandle)) Then
Exit;
With Blob^ Do Begin
bufsize := $8192;
total_bytes_write := 0; // total bytes read is 0.
Try
Fs := TFileStream.Create(FileName, fmOpenRead);
Except
On E:EFileStreamError Do Begin
Exit;
End;
End;
GetMem(buff,bufsize);
Try
Repeat
Try
bytes_read := Fs.read(buff^, bufsize);
Except
On E:EINOutError Do Begin
Exit;
End
End;
PutSegment(BlobHandle, buff, bytes_read);
Inc(total_bytes_write, bytes_read);
Until Fs.Size <= total_bytes_write;
Finally
FreeMem(buff);
Fs.Free;
End;
End;
end;
function WriteBlobToFile(FileName: PChar; Blob: PBlob): integer; Cdecl;
export;
var
bytes_read, bufsize :Integer;
total_bytes_read :Integer;
buff :PAnsiChar; //pointer;
Fs :TFileStream;
begin
result := 0;
If (Not Assigned(Blob)) Or (Not Assigned(Blob^.BlobHandle)) Then
Exit;
ForceDirectories(Copy(StrPas(FileName), 1, LastDelimiter(PathDelim,
StrPas(FileName))));
with Blob^ do begin
bufsize := MaxSegmentLength; // char and varchar can't handle more
bytes;
If TotalSize = 0 Then
Exit; // if I've nothing to copy, exit.
total_bytes_read := 0; // total bytes read is 0.
Try
Fs := TFileStream.Create(FileName, fmCreate Or fmShareExclusive);
Except
On E:EFCreateError Do Begin
Result := -1;
Exit;
End;
End;
GetMem(buff, MaxSegmentLength);
Try
Repeat
// Using BlobHandle, store at most "bytes_left" bytes in
// the buffer starting where I last left off
bytes_read := 0;
GetSegment(BlobHandle, buff, bufsize, bytes_read);
Try
Fs.Write(buff^,bytes_read);
Except
On E:EINOutError Do Begin
Result := E.ErrorCode;
Exit;
End;
End;
// Increment total_bytes_read by the number of bytes actually read.
Inc(total_bytes_read, bytes_read);
Until TotalSize <= total_bytes_read;
Finally
FreeMem(buff);
Fs.Free;
End;
End;
end;
Regards
Janex