Attachments via SOAP
Attachments via SOAP
Ich suche mittlerweile Ewigkeiten nach einer Lösung um Attachments via SOAP zu übertragen. Prinzipiell ist es möglich Attachments zu übertragen, leider aber nur als Plaintext. Sobald ich versuche Binary-Data zu übertragen meckert SOAP bzgl. des Encodings.
Übertrage ich die Attachments als Base64-codierte Daten, funktioniert zwar die Übertragung, aber OTRS decodiert diese nicht wieder - die Datei ist also nicht lesbar.
Hat jemanden vllt. einen Code Schnipsel mit dem man das ändern könnte? Oder gibt es einen anderen Weg Attachments zu Tickets hinzuzufügen?
Leider beherrsche ich selbst kaum PERL so dass ich mir nicht selbst schnell einen Hack schreiben könnte.
Vielen Dank für Anregungen und Hilfe.
Übertrage ich die Attachments als Base64-codierte Daten, funktioniert zwar die Übertragung, aber OTRS decodiert diese nicht wieder - die Datei ist also nicht lesbar.
Hat jemanden vllt. einen Code Schnipsel mit dem man das ändern könnte? Oder gibt es einen anderen Weg Attachments zu Tickets hinzuzufügen?
Leider beherrsche ich selbst kaum PERL so dass ich mir nicht selbst schnell einen Hack schreiben könnte.
Vielen Dank für Anregungen und Hilfe.
-
- Znuny newbie
- Posts: 7
- Joined: 13 Nov 2010, 14:41
- Znuny Version: 2
Re: Attachments via SOAP
Hi,
have you find the solution? I have the sam problem.
Thank you
Francesco
have you find the solution? I have the sam problem.
Thank you
Francesco
-
- Znuny guru
- Posts: 2189
- Joined: 08 Dec 2005, 17:01
- Znuny Version: 5.0.x
- Real Name: André Bauer
- Company: Magix Software GmbH
- Location: Dresden
- Contact:
Re: Attachments via SOAP
Maybe it would help if you post your code...
Prod: Ubuntu Server 16.04 / Zammad 1.2
DO NOT PM ME WITH OTRS RELATED QUESTIONS! ASK IN THE FORUMS!
OtterHub.org
DO NOT PM ME WITH OTRS RELATED QUESTIONS! ASK IN THE FORUMS!
OtterHub.org
-
- Znuny newbie
- Posts: 7
- Joined: 13 Nov 2010, 14:41
- Znuny Version: 2
Re: Attachments via SOAP
I don't have a code because I don't know how to do it. Have you got any idea?
Thank you
Thank you
Re: Attachments via SOAP
I also have the same issue with Attachments like pdf/jpg/xls etc.
My php code works ony for html/txt files.
Error code:
Fatal error: SOAP-ERROR: Encoding: string '%PDF-1.5 %\xb5...' is not a valid utf-8 string in
Have you got any idea?
Thank you
My php code works ony for html/txt files.
Code: Select all
Code:
$myFile = "c:\\contact.htm";
$fh = fopen($myFile,'rb') or die($php_errormsg);
$theData = fread($fh,filesize($myFile));
fclose($fh) or die($php_errormsg);
$articleattachment = $soapclient->__soapCall("Dispatch", array($user, $pass, "TicketObject", "ArticleWriteAttachment",
"Content", $theData,
"ContentType", "text/html",
"Filename", $myFile,
# "ContentID => 'cid-1234', # optional
# ContentAlternative => 0, # optional, alternative content to shown as body
"ArticleID", $articleid,
"UserID",$userid
));
Fatal error: SOAP-ERROR: Encoding: string '%PDF-1.5 %\xb5...' is not a valid utf-8 string in
Have you got any idea?
Thank you
-
- Znuny newbie
- Posts: 7
- Joined: 13 Nov 2010, 14:41
- Znuny Version: 2
Re: Attachments via SOAP
Hello,
I had the same problem and I had just arrived at a possible solution. But I had not more time, so I had to find an alternative.
Through the web services I create the ticket and the article. Then I transfer the files via ftp in the folder reference. OTRS, if set to save the attachment to disk, when you create a ticket and the article in automatic it create on the disk a path like this: <year> / <month> / <day> / <articleid returned by ws> where when you put the file via ftp it automatically makes you see it in the web interface. In addition you must put a file called <articleid>. <file extension>. content_type which contains a line describing the content type. Sample Content: application/pdf. I eventually solved the case. You can do the same thing even if you save the file in the db. Instead of loading the file via ftp load it in the db.
I hope I was clear.
Bye
I had the same problem and I had just arrived at a possible solution. But I had not more time, so I had to find an alternative.
Through the web services I create the ticket and the article. Then I transfer the files via ftp in the folder reference. OTRS, if set to save the attachment to disk, when you create a ticket and the article in automatic it create on the disk a path like this: <year> / <month> / <day> / <articleid returned by ws> where when you put the file via ftp it automatically makes you see it in the web interface. In addition you must put a file called <articleid>. <file extension>. content_type which contains a line describing the content type. Sample Content: application/pdf. I eventually solved the case. You can do the same thing even if you save the file in the db. Instead of loading the file via ftp load it in the db.
I hope I was clear.
Bye
Re: Attachments via SOAP
Hi,
thank you! That was a good help and it creates the Ticket and the Attachment.
My problem now is that I also want to send the attachments together with the the article.
The code in the SOAP API ArticleSend includes the Attachment:
How can you send the Article together with the Attachments when they are stored in the FS system? How did you solve this?
thank you! That was a good help and it creates the Ticket and the Attachment.
My problem now is that I also want to send the attachments together with the the article.
The code in the SOAP API ArticleSend includes the Attachment:
Code: Select all
my $ArticleID = $TicketObject->ArticleSend(
TicketID => 123,
ArticleType => 'note-internal', # email-external|email-internal|phone|fax|...
SenderType => 'agent', # agent|system|customer
From => 'Some Agent <email@example.com>', # not required but useful
To => 'Some Customer A <customer-a@example.com>', # not required but useful
Cc => 'Some Customer B <customer-b@example.com>', # not required but useful
ReplyTo => 'Some Customer B <customer-b@example.com>', # not required
Subject => 'some short description', # required
Body => 'the message text', # required
InReplyTo => '<asdasdasd.12@example.com>', # not required but useful
References => '<asdasdasd.1@example.com> <asdasdasd.12@example.com>', # not required but useful
Charset => 'iso-8859-15'
MimeType => 'text/plain',
Loop => 0, # 1|0 used for bulk emails
Attachment => [
{
Content => $Content,
ContentType => $ContentType,
Filename => 'lala.txt',
},
{
Content => $Content,
ContentType => $ContentType,
Filename => 'lala1.txt',
},
],
Sign => {
Type => 'PGP',
SubType => 'Inline|Detached',
Key => '81877F5E',
Type => 'SMIME',
Key => '3b630c80',
},
Crypt => {
Type => 'PGP',
SubType => 'Inline|Detached',
Key => '81877F5E',
Type => 'SMIME',
Key => '3b630c80',
},
HistoryType => 'OwnerUpdate', # Move|AddNote|PriorityUpdate|WebRequestCustomer|...
HistoryComment => 'Some free text!',
NoAgentNotify => 0, # if you don't want to send agent notifications
UserID => 123,
);
Re: Attachments via SOAP
Some time ago I found a solution for that problem. I'm not a PERL programmer, but it worked for me and solved my problem since then.
It only works, if you specify the new parameter "IsBase64Encoded" as I did not find a solution for recognizing base64 encoded data.
It only works, if you specify the new parameter "IsBase64Encoded" as I did not find a solution for recognizing base64 encoded data.
Code: Select all
root@www:~/otrs-2.4.7/Kernel# diff -r ./System/Ticket/Article.pm /usr/share/otrs/Kernel/System/Ticket/Article.pm
260a261,272
> if ( $Param{Attachment} ) {
>
> use MIME::Base64;
>
> for my $Attachment ( @{ $Param{Attachment} } ) {
> if (defined $Attachment->{IsBase64Encoded} ) {
> $Self->{LogObject}->Log( Priority => 'error', Message => "base64 decoding $Attachment->{Filename}");
> $Attachment->{Content} = decode_base64($Attachment->{Content});
> }
> }
> }
>
Re: Attachments via SOAP
Thank you Francesco and Shihan, I had made some progress, but I still have the problem to use ArticleSend() with Attachments like .jpg.
- I changed the Attachment from the DB to FS and I am able to create Attachments on the fly with the ftp, php code, but I was not able to send this attachments with ArticleSend so I was trying to do it with the changes in the Article.pm
- I did the change in the Article.pm and I added before ( # add converted attachments) the addtional lines, but when I use binary attachments it still comes the same SOAP Error Message:
Fatal error: SOAP-ERROR: Encoding: string '\xff...' is not a valid utf-8 string in
Here the code I using:
There is no additional log in the OTRS log file..
Again the only thing I want to do is sending from OTRS a Ticket with attachments like jpeg, pdf, etc.
Changes on Ticket.pm:
Should I do also something on the php code to encode the Attachments? Did you also pass the File with fread() to the variable or you did it in a different way?
Do you know another workaround to send ticket with binary attachments?
- I changed the Attachment from the DB to FS and I am able to create Attachments on the fly with the ftp, php code, but I was not able to send this attachments with ArticleSend so I was trying to do it with the changes in the Article.pm
- I did the change in the Article.pm and I added before ( # add converted attachments) the addtional lines, but when I use binary attachments it still comes the same SOAP Error Message:
Fatal error: SOAP-ERROR: Encoding: string '\xff...' is not a valid utf-8 string in
Here the code I using:
Code: Select all
#$myFile = "contact.htm"; # HTML FILE WORKS
#$contenttype = "text/plain"; # HTML FILE WORKS
$myFile = "CristmasCard.jpg"; #JPG FILE DOESN'T WORKS
$contenttype = "IsBase64Encoded"; #JPG FILE DOESN'T WORKS
$mydirFile = $mydir . $myFile;
$fh = fopen($mydirFile,'rb') or die($php_errormsg);
$theData = fread($fh,filesize($mydirFile));
fclose($fh) or die($php_errormsg);
$articleid = $soapclient->__soapCall("Dispatch", array($user, $pass, "TicketObject", "ArticleSend",
"TicketID" , $ticketid,
"ArticleType" , "email-external",
"SenderType" , "agent",
"From" , $from,
"To" , $to,
"ReplyTo" , "",
"Subject" , "[ Ticket#: ".$ticketnr." ] ".$subject,
"Body" , $message,
"ContentType" , "text/plain; charset=utf-8",
"Charset" , "utf-8",
"HistoryType" , "EmailCustomer",
"HistoryComment" , "generated by OTRSInterface-Class",
"NoAgentNotify" , 0,
"MimeType" , "text/html",
"Loop" , 0 ,
"Attachment" , array(
array('Content' => $theData,'ContentType' => $contenttype,'Filename' => $myFile),
# array('Content' => $theData,'ContentType' => $contenttype,'Filename' => $myFile)
),
"UserID" , $userid
));
Again the only thing I want to do is sending from OTRS a Ticket with attachments like jpeg, pdf, etc.
Changes on Ticket.pm:
Should I do also something on the php code to encode the Attachments? Did you also pass the File with fread() to the variable or you did it in a different way?
Do you know another workaround to send ticket with binary attachments?
Re: Attachments via SOAP
Sending binary attachments works. You have to specifiy the paramter IsBase64Encoded for
every attachment and you have to encode the attachments. Yo did not do any of these things.
every attachment and you have to encode the attachments. Yo did not do any of these things.
-
- Znuny newbie
- Posts: 7
- Joined: 13 Nov 2010, 14:41
- Znuny Version: 2
Re: Attachments via SOAP
In my case, when I called call ArticleSend I not send the information about attachment. As I said, when you create a ticket object and article OTRS automatically creates the folder on disk where you can put the files. The only thing I forgot to tell you is that you must pass the following parameters as follows
"ContentType", "text / html; charset = utf-8"
"Body", "<html> <head> <meta http-equiv = \" Content-Type \ "content = \"text / html; charset = utf-8 \ "</ head> <body> </ body> </ html> "
I am attaching my sample php. There is no part of the FTP connection
I hope I was clear,
Bye
Francesco
"ContentType", "text / html; charset = utf-8"
"Body", "<html> <head> <meta http-equiv = \" Content-Type \ "content = \"text / html; charset = utf-8 \ "</ head> <body> </ body> </ html> "
I am attaching my sample php. There is no part of the FTP connection
I hope I was clear,
Bye
Francesco
You do not have the required permissions to view the files attached to this post.
Re: Attachments via SOAP
Hi Shihan,
- I said I have modified the Ticket.pm but this is not correct, I modified the Article.pm and I added the addtional line to this.
- Also I added the $theData = base64_encode($theData); in the php code to use the base64 encoding.
So but the decoding doesn't works. I am using OTRS 3.0.4, perhaps there are changes in the Article.pm
Could you please send me your complete Article.pm
Thank you
Horst
- I said I have modified the Ticket.pm but this is not correct, I modified the Article.pm and I added the addtional line to this.
- Also I added the $theData = base64_encode($theData); in the php code to use the base64 encoding.
After the change in the php code the sending of the attachments works. (This is what you said)shihan wrote:Sending binary attachments works. You have to specifiy the paramter IsBase64Encoded for
every attachment and you have to encode the attachments. Yo did not do any of these things.
So but the decoding doesn't works. I am using OTRS 3.0.4, perhaps there are changes in the Article.pm
Could you please send me your complete Article.pm
Thank you
Horst
Re: Attachments via SOAP
Here's the complete file. Search for "64". It is Version 2.4.7 of OTRS.
http://nopaste.php-quake.net/387428
http://nopaste.php-quake.net/387428
Re: Attachments via SOAP [SOLVED]
Hi Shihan,
finaly now it works, I had to modify a little bit your perl code, because it did not worked with OTRS 3.0.4
Attached the code, perhaps somebody runs in the same issues:
Thank you again Shihan and francescod for the really fast response!
finaly now it works, I had to modify a little bit your perl code, because it did not worked with OTRS 3.0.4
Attached the code, perhaps somebody runs in the same issues:
Code: Select all
# add attachments
if ( $Param{Attachment} ) {
if ( $Param{Attachment} ) {
use MIME::Base64;
for my $Attachment ( @{ $Param{Attachment} } ) {
my $tmpcontenttype = $Attachment->{ContentType};
if ($tmpcontenttype eq "IsBase64Encoded" ) {
$Self->{LogObject}->Log( Priority => 'error', Message => "base64 decoding $Attachment->{Filename}");
$Attachment->{Content} = decode_base64($Attachment->{Content});
}
}
}
for my $Attachment ( @{ $Param{Attachment} } ) {
$Self->ArticleWriteAttachment(
%{$Attachment},
ArticleID => $ArticleID,
UserID => $Param{UserID},
);
}
}
Re: Attachments via SOAP
Hello,
if have nearly the same file like francescods sample php. And i have added
if have nearly the same file like francescods sample php. And i have added
this to my Article.pm. But really don't know what to add to the php/perl file? Can you attache a sample with the attachment function? Or jut tell what i have to add, to send attachments via soap with the ticket?horst wrote:Hi Shihan,
finaly now it works, I had to modify a little bit your perl code, because it did not worked with OTRS 3.0.4
Attached the code, perhaps somebody runs in the same issues:Thank you again Shihan and francescod for the really fast response!Code: Select all
# add attachments if ( $Param{Attachment} ) { if ( $Param{Attachment} ) { use MIME::Base64; for my $Attachment ( @{ $Param{Attachment} } ) { my $tmpcontenttype = $Attachment->{ContentType}; if ($tmpcontenttype eq "IsBase64Encoded" ) { $Self->{LogObject}->Log( Priority => 'error', Message => "base64 decoding $Attachment->{Filename}"); $Attachment->{Content} = decode_base64($Attachment->{Content}); } } } for my $Attachment ( @{ $Param{Attachment} } ) { $Self->ArticleWriteAttachment( %{$Attachment}, ArticleID => $ArticleID, UserID => $Param{UserID}, ); } }
Re: Attachments via SOAP
Hello,
please you this code:
Important is this: $contenttype = "IsBase64Encoded" to use the decode_base64 function
please you this code:
Code: Select all
#$myFile = "contact.htm"; # HTML FILE WORKS
#$contenttype = "text/plain"; # HTML FILE WORKS
$myFile = "CristmasCard.jpg"; #JPG FILE DOESN'T WORKS
$contenttype = "IsBase64Encoded"; #JPG FILE DOESN'T WORKS
$mydirFile = $mydir . $myFile;
$fh = fopen($mydirFile,'rb') or die($php_errormsg);
$theData = fread($fh,filesize($mydirFile));
fclose($fh) or die($php_errormsg);
$articleid = $soapclient->__soapCall("Dispatch", array($user, $pass, "TicketObject", "ArticleSend",
"TicketID" , $ticketid,
"ArticleType" , "email-external",
"SenderType" , "agent",
"From" , $from,
"To" , $to,
"ReplyTo" , "",
"Subject" , "[ Ticket#: ".$ticketnr." ] ".$subject,
"Body" , $message,
"ContentType" , "text/plain; charset=utf-8",
"Charset" , "utf-8",
"HistoryType" , "EmailCustomer",
"HistoryComment" , "generated by OTRSInterface-Class",
"NoAgentNotify" , 0,
"MimeType" , "text/html",
"Loop" , 0 ,
"Attachment" , array(
array('Content' => $theData,'ContentType' => $contenttype,'Filename' => $myFile),
# array('Content' => $theData,'ContentType' => $contenttype,'Filename' => $myFile)
),
"UserID" , $userid
));
Brassmann wrote:Hello,
if have nearly the same file like francescods sample php. And i have addedthis to my Article.pm. But really don't know what to add to the php/perl file? Can you attache a sample with the attachment function? Or jut tell what i have to add, to send attachments via soap with the ticket?horst wrote:Hi Shihan,
finaly now it works, I had to modify a little bit your perl code, because it did not worked with OTRS 3.0.4
Attached the code, perhaps somebody runs in the same issues:Thank you again Shihan and francescod for the really fast response!Code: Select all
# add attachments if ( $Param{Attachment} ) { if ( $Param{Attachment} ) { use MIME::Base64; for my $Attachment ( @{ $Param{Attachment} } ) { my $tmpcontenttype = $Attachment->{ContentType}; if ($tmpcontenttype eq "IsBase64Encoded" ) { $Self->{LogObject}->Log( Priority => 'error', Message => "base64 decoding $Attachment->{Filename}"); $Attachment->{Content} = decode_base64($Attachment->{Content}); } } } for my $Attachment ( @{ $Param{Attachment} } ) { $Self->ArticleWriteAttachment( %{$Attachment}, ArticleID => $ArticleID, UserID => $Param{UserID}, ); } }
Re: Attachments via SOAP
Oh, can you start a little bit further? I've never worked with files before. What I have to do to get a file to work with like that?
Re: Attachments via SOAP
Hi!
I solved this problem.
It's work for me.
Good luck)
I solved this problem.
Magic here new SoapVar(file_get_contents($attachment['tmp_name']),XSD_BASE64BINARY, 'xsd:base64Binary').$soapclient->__soapCall("Dispatch", array(
$username, $password,
"TicketObject", "ArticleWriteAttachment",
"Content", new SoapVar(file_get_contents($attachment['tmp_name']),XSD_BASE64BINARY, 'xsd:base64Binary'),
"ContentType", $attachment['type'],
"Filename", $attachment['name'],
"ArticleID", $articleId,
"UserID", 1
);
It's work for me.
Good luck)
-
- Znuny newbie
- Posts: 1
- Joined: 15 Feb 2012, 00:42
- Znuny Version: 30000
- Real Name: Donna
- Company: Activation LLC
- Contact:
Re: Attachments via SOAP
I will try all your suggestions guys. I was actually planning to do some thing like this. Thanks.
Re: Attachments via SOAP
Thank You very much. It got it working
Here what i put in my form-script:
...
<form action="<?php print $_SERVER["PHP_SELF"]; ?>" method="post" accept-charset="UTF8" enctype="multipart/form-data">
...
<label for='uploaded_file'>Select a file to upload:</label>
<input type="file" name="uploaded_file">
...
$client->__soapCall("Dispatch", array(
$username,
$password,
"TicketObject", "ArticleWriteAttachment",
"Content", new SoapVar(file_get_contents($_FILES["uploaded_file"]['tmp_name']),XSD_BASE64BINARY, 'xsd:base64Binary'),
"ContentType", $_FILES["uploaded_file"]['type'],
"Filename", $_FILES["uploaded_file"]['name'],
"ArticleID", $ArticleID,
"UserID", 1
));
Maybe there are another people don't knowing how to get the file in the form.
Greetings
Brassmann
Here what i put in my form-script:
...
<form action="<?php print $_SERVER["PHP_SELF"]; ?>" method="post" accept-charset="UTF8" enctype="multipart/form-data">
...
<label for='uploaded_file'>Select a file to upload:</label>
<input type="file" name="uploaded_file">
...
$client->__soapCall("Dispatch", array(
$username,
$password,
"TicketObject", "ArticleWriteAttachment",
"Content", new SoapVar(file_get_contents($_FILES["uploaded_file"]['tmp_name']),XSD_BASE64BINARY, 'xsd:base64Binary'),
"ContentType", $_FILES["uploaded_file"]['type'],
"Filename", $_FILES["uploaded_file"]['name'],
"ArticleID", $ArticleID,
"UserID", 1
));
Maybe there are another people don't knowing how to get the file in the form.
Greetings
Brassmann
-
- Znuny newbie
- Posts: 23
- Joined: 07 Jun 2012, 09:20
- Znuny Version: 3.1.5
- Real Name: denbagus
- Company: indolabsoft
Re: Attachments via SOAP
still get error when try adding attachment via soap.
on system log. and the attchment not appear on my otrs.
i want to add attachment jpg file from file system, not uploaded form processing. but i get this message...
<form action="<?php print $_SERVER["PHP_SELF"]; ?>" method="post" accept-charset="UTF8" enctype="multipart/form-data">
...
<label for='uploaded_file'>Select a file to upload:</label>
<input type="file" name="uploaded_file">
...
$client->__soapCall("Dispatch", array(
$username,
$password,
"TicketObject", "ArticleWriteAttachment",
"Content", new SoapVar(file_get_contents($_FILES["uploaded_file"]['tmp_name']),XSD_BASE64BINARY, 'xsd:base64Binary'),
"ContentType", $_FILES["uploaded_file"]['type'],
"Filename", $_FILES["uploaded_file"]['name'],
"ArticleID", $ArticleID,
"UserID", 1
));
Code: Select all
Need Content!
-
- Znuny newbie
- Posts: 23
- Joined: 07 Jun 2012, 09:20
- Znuny Version: 3.1.5
- Real Name: denbagus
- Company: indolabsoft
Re: Attachments via SOAP
i change this
thanks
to absolute location of my attachment file. and now its works perfectly.$_FILES["uploaded_file"]['tmp_name']
thanks
-
- Znuny newbie
- Posts: 2
- Joined: 12 Jan 2013, 11:32
- Znuny Version: 3.0.10
- Real Name: chris adams
- Company: Abdo
- Location: Muscat, Oman
- Contact:
Re: Attachments via SOAP
Actually SOAP applications often have to deal with more than just simple messages. The payload for a SOAP message can often include a word processing or PDF document, image, or other binary file. I hope, this could help you in dealing with errors.