So... Ich habs jetzt hinbekommen...
Da das ganze wie gesagt Neuland ist für mich, würd mich Eure Meinung dazu (also zu meiner Lösung) interessieren:
MS
SQL Tabelle (quick & dirty angelegt zum Testen):
Code:
Create Table [mailsolution].[dbo].[mailsolution.attachments]
(
AttachmentName varchar(255),
AttachmentExt varchar(25),
AttachmentBlob varbinary(max)
)
Upload in MS
SQL Tabelle
Delphi-Quellcode:
//******************************************************************************
// OnClick btn_upload *
//******************************************************************************
procedure Tmain_form.btn_uploadClick(Sender: TObject);
var
ms : TMemoryStream;
begin
Try
ms := TMemoryStream.Create;
ms.LoadFromFile(edt_attachmentpath.Text);
Try
With (dmunidb.UniDB_Query1)
Do
Begin
Active := False;
SQL.Clear;
SQL.Add('
Insert Into "mailsolution.Attachments" ');
SQL.Add('
(AttachmentName, AttachmentExt, AttachmentBlob) ');
SQL.Add('
Values(:AttachmentName, :AttachmentExt, :AttachmentBlob) ');
ParamByName('
AttachmentName').AsString := '
Test';
ParamByName('
AttachmentExt').AsString := '
.pdf';
ParamByName('
AttachmentBlob').SetBlobData(ms.Memory, ms.Size);
ExecSQL;
End;
Except
On E:
Exception Do
Begin
MessageDlg(E.
Message, mtError, [mbOK], 0);
End;
End;
Finally
ms.Free;
End;
end;
Download aus MS
SQL Tabelle:
Delphi-Quellcode:
//******************************************************************************
// OnClick btn_download *
//******************************************************************************
procedure Tmain_form.btn_downloadClick(Sender: TObject);
var
ts: TStream;
ms: TMemoryStream;
begin
Try
With (dmunidb.UniDB_Query1)
Do
Begin
Active := False;
SQL.Clear;
SQL.Add('
Select * From "mailsolution.Attachments" ');
ExecSQL;
End;
Except
On E:
Exception Do
Begin
MessageDlg(E.
Message, mtError, [mbOK], 0);
End;
End;
Try
ts := TStream.Create;
ts := dmunidb.UniDB_Query1.CreateBlobStream(dmunidb.UniDB_Query1.Fieldbyname('
AttachmentBlob'),bmRead);
ms := TMemoryStream.Create;
ms.LoadFromStream(ts);
ms.SaveToFile(edt_savepath.Text);
Finally
ts.Free;
ms.Free;
End;
end;