Search code examples
laravel-5.5swiftmailer

Swift_Attachment - how to get path of the attachment file


Using the Swift_Attachment API I can get the file name getFilename() but I can't find a way to get the full path of the file.

I'm using Laravel 5.5 and this email_log library but need to modify it so the files are not stored in the database.

I've reached the attachments using Swift_Message->getChildren() and inside of it there is

-body: Swift_ByteStream_FileByteStream { 
  ...
  -path: "/root/path/to/my/file"
  ...
}

If I could get the -body as a Swift_ByteStream_FileByteStream instance then I could use the getPath() from here but I don't know how to do that.


Solution

  • Decided to store the file from the attachment and not from the path as I couldn't find a way to extract the path.

        $messageId = strtok($message->getId(), '@');
        foreach ($message->getChildren() as $child) {
            $attachmentPath = 'email_log_attachments/' . $messageId . '/' . $child->getFilename();
            Storage::put($attachmentPath,$child->getBody());
        }