-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
A1Gard
committed
Dec 16, 2016
1 parent
b4d2a41
commit 3de63b5
Showing
4 changed files
with
110 additions
and
45 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
unit uFileCls; | ||
|
||
{$mode objfpc}{$H+} | ||
|
||
interface | ||
|
||
uses | ||
Classes, SysUtils,process; | ||
|
||
type | ||
TgFile = class(TObject) | ||
public | ||
constructor Create(tgUrl:String); | ||
function SendFileFromUrl(chat_id,fileUrl,caption:String;var mem: TMemoryStream):Boolean; | ||
function SendFileFromLocation(chat_id,fullAddPath,caption:String;var mem: TMemoryStream):Boolean; | ||
//function | ||
private | ||
var | ||
_TgURL_ : String; | ||
protected | ||
|
||
end; | ||
|
||
implementation | ||
|
||
constructor TgFile.Create(tgUrl:String); | ||
begin | ||
_TgURL_ := tgUrl; | ||
end; | ||
|
||
|
||
|
||
function TgFile.SendFileFromLocation(chat_id,fullAddPath,caption:String;var mem: TMemoryStream):Boolean; | ||
var | ||
r: string; | ||
begin | ||
if RunCommand('/usr/bin/curl', ['-o', ExtractFileDir(ExeName) + | ||
'/catch', _TgURL_ + 'chat_id='+ chat_id + '&caption='+ caption, '-H', | ||
'Content-Type:multipart/form-data','--form','photo=@'+fullAddPath+';type=image/jpeg'], | ||
r) then | ||
begin | ||
mem.LoadFromFile(ExtractFileDir(ExeName) + '/catch'); | ||
end; | ||
Result := True; | ||
|
||
end; | ||
|
||
|
||
|
||
function TgFile.SendFileFromUrl(chat_id,fileUrl,caption:String;var mem: TMemoryStream):Boolean; | ||
var | ||
r: string; | ||
begin | ||
|
||
if RunCommand('/usr/bin/curl', ['-o', ExtractFileDir(ExeName) + | ||
'/tmp', fileUrl, r) then | ||
begin | ||
Result := SendFileFromLocation(chat_id,ExtractFileDir(ExeName) + | ||
'/tmp',caption,mem); | ||
end | ||
else | ||
begin | ||
Result := False; | ||
Exit; | ||
end; | ||
//WriteLn('/usr/bin/curl',['-o',ExtractFileDir(ExeName)+'/catch',url]); | ||
|
||
end; | ||
|
||
end. | ||
|
||
|