Using file objects in a mail message (Dashboard Single Page)

Permalink 1 user found helpful
I try to attach a file object to the
$mail = Loader::helper('mail');

I have included the following in the form of my view:
$f = new Concrete\Core\Application\Service\FileManager();
//...
echo $f->file('file', 'test', 'pls choose');

Then I submit my form back to the controller. There (BTW all other form fields arrive in the contorller as expected) I do:
$files = $this->post('test');
$file = \File::getByID($files);

which returns a File object. Should do, because when I do
$file = \File::getRelativePathFromID($files);
it gives me the correct path to the chosen file.

So far so good. BUT when I try to send a mail with exactly that file object attached:
$mail = Loader::helper('mail');
        $mail->setTesting(false);
        $mail->setSubject('test-subject');
        $mail->to($this->post('uEmail'));
//...
$attach = $mail->addAttachment($file);
        $attach->filename = 'tttt';
        $mail->sendMail();
the following error occurs:
call_user_func_array() expects parameter 1 to be a valid callback, class 'Concrete\Core\File\Version' does not have a method 'getPath'
which apparently comes from this class method:
namespace Concrete\Core\Mail;
//...
class Service {
//...
/**
      * Add attachment to send with an email.
      *
//... example
      *
      * @param File $fob File to attach
      * @return StdClass Pointer to the attachment
      */
public function addAttachment(\Concrete\Core\File\File $fob)
    {
         // @TODO make this work with the File Storage Locations
which apparently wants a file object as param, which I think I gave it, weren't I?
Why my file object becomes a FileVersion, which, as I see by myself, hasn't got a method getPath().


So after hours of trying around with File & FileVersion/.. I'd be glad to get some help please!

How do I get the correct file object, which I have to, apparently , take out of the last Version of this file?

daenu
 
daenu replied on at Permalink Best Answer Reply
daenu
This was a bug:https://github.com/concrete5/concrete5-5.7.0/issues/1765... that has been fixed in the upstream:https://github.com/concrete5/concrete5-5.7.0/commit/cf3e9680a5f4b6c7... .
We'll have to either patch this by ourselfs or wait until version 7.4 lands.
Thx to SO user Korvin Szanto.
I should really read the github bug messages!!!