sahilpaudel

sahilpaudel

(FunctionClauseError) no function clause matching in Base.encode64/2

I am trying to send attachment inside email from my phoenix application using Bamboo.

Library used:
nimble_csv
bamboo
bamboo_smtp

The attachment is in-memory data that I am getting after parsing the CSV and making some changes into it. I don’t want to save the CSV file so using the in-memory approach.

def dump_to_csv(list) do
    [~w(ORIGINAL_URL NEW_URL)] ++ list
      |> ShortnerParser.dump_to_iodata()
      |> prepare_mail
      |> Mailer.deliver_later
  end

def prepare_mail(data) do
    attachment = %Bamboo.Attachment{content_type: "application/octet-stream", filename: "shortner.csv", data: data}
    Email.send_csv("myemail@gmail.com", attachment)
  end

Error I am getting:

[error] Task #PID<0.1556.0> started from #PID<0.1492.0> terminating
** (FunctionClauseError) no function clause matching in Base.encode64/2
    (elixir) lib/base.ex:371: Base.encode64([["ORIGINAL_URL", 44, "NEW_URL", 10], ["https:pharmeasy.in", 44, "invalid_url", 10], ["https://facebook.com", 44, "https://localhost:4000/ldhkRf", 10], ["https://google.com", 44, "https://localhost:4000/n594Hy", 10], ["https:pharmeasy.in", 44, "invalid_url", 10], ["https://facebook.com", 44, "https://localhost:4000/Kl67G5", 10], ["https://google.com", 44, "https://localhost:4000/Ct17TM", 10], ["https:pharmeasy.in", 44, "invalid_url", 10], ["https://facebook.com", 44, "https://localhost:4000/w1gX_x", 10], ["https://google.com", 44, "https://localhost:4000/1lqoLr", 10], ["https:pharmeasy.in", 44, "invalid_url", 10], ["https://facebook.com", 44, "https://localhost:4000/R_u3Yq", 10], ["https://google.com", 44, "https://localhost:4000/elXe4V", 10], ["https:pharmeasy.in", 44, "invalid_url", 10], ["https://facebook.com", 44, "https://localhost:4000/13hn32", 10], ["https://google.com", 44, "https://localhost:4000/j9uiKL", 10], ["https:pharmeasy.in", 44, "invalid_url", 10], ["https://facebook.com", 44, "https://localhost:4000/c3pzUB", 10], ["https://google.com", 44, "https://localhost:4000/Yhb7Kv", 10], ["https:pharmeasy.in", 44, "invalid_url", 10], ["https://facebook.com", 44, "https://localhost:4000/19PS7z", 10], ["https://google.com", 44, "https://localhost:4000/LvHqO1", 10], ["https:pharmeasy.in", 44, "invalid_url", 10], ["https://facebook.com", 44, "https://localhost:4000/teJagz", 10], ["https://google.com", 44, "https://localhost:4000/MBYX_e", 10], ["https:pharmeasy.in", 44, "invalid_url", 10], ["https://facebook.com", 44, "https://localhost:4000/DfpQ25", 10], ["https://google.com", 44, "https://localhost:4000/jLFq6P", 10], ["https:pharmeasy.in", 44, "invalid_url", 10], ["https://facebook.com", 44, "https://localhost:4000/xM7Jg3", 10], ["https://google.com", 44, "https://localhost:4000/IM2RG6", 10], ["https:pharmeasy.in", 44, "invalid_url", 10], ["https://facebook.com", 44, "https://localhost:4000/1X2IZ8", 10], ["https://google.com", 44, "https://localhost:4000/KKo0kt", 10], ["https:pharmeasy.in", 44, "invalid_url", 10], ["https://facebook.com", 44, "https://localhost:4000/YvTW_p", 10], ["https://google.com", 44, "https://localhost:4000/iwLt7L", 10], ["https:pharmeasy.in", 44, "invalid_url", 10], ["https://facebook.com", 44, "https://localhost:4000/DoIvwE", 10], ["https://google.com", 44, "https://localhost:4000/ZMe3dE", 10], ["https:pharmeasy.in", 44, "invalid_url", 10], ["https://facebook.com", 44, "https://localhost:4000/CGEIa1", 10], ["https://google.com", 44, "https://localhost:4000/Z6fPMT", 10], ["https:pharmeasy.in", 44, "invalid_url", 10], ["https://facebook.com", 44, "https://localhost:4000/zYpNgG", 10], ["https://google.com", 44, "https://localhost:4000/MYQdRu", 10], ["https:pharmeasy.in", 44, "invalid_url", ...], ["https://facebook.com", 44, ...], ["https://google.com", ...], [...], ...], [])
    (bamboo_smtp) lib/bamboo/adapters/smtp_adapter.ex:214: Bamboo.SMTPAdapter.add_attachment_body/2
    (elixir) lib/enum.ex:1314: Enum."-map/2-lists^map/1-0-"/2
    (bamboo_smtp) lib/bamboo/adapters/smtp_adapter.ex:233: Bamboo.SMTPAdapter.add_attachments/3
    (bamboo_smtp) lib/bamboo/adapters/smtp_adapter.ex:278: Bamboo.SMTPAdapter.body/1
    (bamboo_smtp) lib/bamboo/adapters/smtp_adapter.ex:360: Bamboo.SMTPAdapter.to_gen_smtp_message/1
    (bamboo_smtp) lib/bamboo/adapters/smtp_adapter.ex:76: Bamboo.SMTPAdapter.deliver/2
    (elixir) lib/task/supervised.ex:89: Task.Supervised.do_apply/2
    (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3
Function: #Function<0.73693256/0 in Bamboo.TaskSupervisorStrategy.deliver_later/3>
    Args: []

Marked As Solved

NobbZ

NobbZ

You need to pass in a binary, rather than iodata.

Also Liked

sahilpaudel

sahilpaudel

How can I do that can you please help me with that?

Sorry that was lame question below method did the trick.

def convert_to_binary(data) do
    data
      |> IO.iodata_to_binary
  end

Thanks.

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

I could be wrong, but I think to_string is not equivalent to IO.iodata_to_binary. to_string expects a list of codepoints, but IO.iodata_to_binary expects any integers in the list to be bytes:

iex(2)> "hełło" |> String.to_charlist |> IO.iodata_to_binary
** (ArgumentError) argument error
    :erlang.iolist_to_binary([104, 101, 322, 322, 111])
iex(2)> "hełło" |> String.to_charlist |> to_string          
"hełło"

I don’t know if this makes any difference if what you start with is an iolist though.

Where Next?

Popular in Questions Top

vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID&lt;0.412.0&gt; terminating ** (Postgrex.Error) FATAL...
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
nobody
How to bind a phoenix app to a specific ip address? could not find anything about that, nowhere, unfortunately, but for me this is quite...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
marick
I had some trouble figuring out how to make many-to-many associations work. Once I got it working, I wrote a blog post. Because I’m a nov...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New

Other popular topics Top

aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 42920 311
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New

We're in Beta

About us Mission Statement