Skip to content

Change attachment struct to support file data instead of filename #286

@sbrink

Description

@sbrink

I propose that we change the current Attachement struct before releasing version 1.0.

Why?

At the moment an attachment struct looks like this:

defstruct filename: nil, content_type: nil, path: nil

This only allows uploads from the file system, not dynamically generated contents.
An use case for generated contents would be .ics files. You want to append a
generated .ics file for adding an event to the user's calendar.

Furthermore every adapter has to implement the correct encoding - this is redundant.
Here's an example I found from a patch for the bamboo_stmp adapter:

defp add_attachment_body(body, attachment) do
  file = File.read!(attachment)
   "#{body}\r\n#{Base.encode64(file)}\r\n"
 end

Proposal:

We change the struct definition to:

defstruct filename: nil, content_type: nil, data: nil

We could:

  1. Split the new function into new_from_data and new_from_attachment
  2. Use pattern matching in the new function

The new new method does the job of file reading and encoding.

What do you think?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions