Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

accept image in base64 encoded format #107

Closed
anoskov opened this issue Sep 7, 2016 · 6 comments
Closed

accept image in base64 encoded format #107

anoskov opened this issue Sep 7, 2016 · 6 comments

Comments

@anoskov
Copy link

anoskov commented Sep 7, 2016

Hello!
In my project, the client uploads the avatar in base 64 format, but now Arc.File.new/1 can't access base64.
I'll add a pull request with this feature.

@stavro
Copy link
Owner

stavro commented Oct 5, 2016

Why is the avatar uploaded in Base64 format? Is this a common thing?

@anoskov
Copy link
Author

anoskov commented Oct 5, 2016

It is a popular way to send image inside json object.

@stavro
Copy link
Owner

stavro commented Oct 6, 2016

I'm not convinced that this is necessary enough to include in Arc.

You can do this with arc / arc_ecto:

user = Blvd.Repo.one!(Blvd.User.Schema)

params = %{
  avatar: %{
    filename: "image.png",
    binary: Base.decode64!("iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAMAAADXqc3KAAAB+FBMVEUAAAA/mUPidDHiLi5Cn0XkNTPmeUrkdUg/m0Q0pEfcpSbwaVdKskg+lUP4zA/iLi3msSHkOjVAmETdJSjtYFE/lkPnRj3sWUs8kkLeqCVIq0fxvhXqUkbVmSjwa1n1yBLepyX1xxP0xRXqUkboST9KukpHpUbuvRrzrhF/ljbwaljuZFM4jELaoSdLtElJrUj1xxP6zwzfqSU4i0HYnydMtUlIqUfywxb60AxZqEXaoifgMCXptR9MtklHpEY2iUHWnSjvvRr70QujkC+pUC/90glMuEnlOjVMt0j70QriLS1LtEnnRj3qUUXfIidOjsxAhcZFo0bjNDH0xxNLr0dIrUdmntVTkMoyfL8jcLBRuErhJyrgKyb4zA/5zg3tYFBBmUTmQTnhMinruBzvvhnxwxZ/st+Ktt5zp9hqota2vtK6y9FemNBblc9HiMiTtMbFtsM6gcPV2r6dwroseLrMrbQrdLGdyKoobKbo3Zh+ynrgVllZulTsXE3rV0pIqUf42UVUo0JyjEHoS0HmsiHRGR/lmRz/1hjqnxjvpRWfwtOhusaz0LRGf7FEfbDVmqHXlJeW0pbXq5bec3fX0nTnzmuJuWvhoFFhm0FtrziBsjaAaDCYWC+uSi6jQS3FsSfLJiTirCOkuCG1KiG+wSC+GBvgyhTszQ64Z77KAAAARXRSTlMAIQRDLyUgCwsE6ebm5ubg2dLR0byXl4FDQzU1NDEuLSUgC+vr6urq6ubb29vb2tra2tG8vLu7u7uXl5eXgYGBgYGBLiUALabIAAABsElEQVQoz12S9VPjQBxHt8VaOA6HE+AOzv1wd7pJk5I2adpCC7RUcHd3d3fXf5PvLkxheD++z+yb7GSRlwD/+Hj/APQCZWxM5M+goF+RMbHK594v+tPoiN1uHxkt+xzt9+R9wnRTZZQpXQ0T5uP1IQxToyOAZiQu5HEpjeA4SWIoksRxNiGC1tRZJ4LNxgHgnU5nJZBDvuDdl8lzQRBsQ+s9PZt7s7Pz8wsL39/DkIfZ4xlB2Gqsq62ta9oxVlVrNZpihFRpGO9fzQw1ms0NDWZz07iGkJmIFH8xxkc3a/WWlubmFkv9AB2SEpDvKxbjidN2faseaNV3zoHXvv7wMODJdkOHAegweAfFPx4G67KluxzottCU9n8CUqXzcIQdXOytAHqXxomvykhEKN9EFutG22p//0rbNvHVxiJywa8yS2KDfV1dfbu31H8jF1RHiTKtWYeHxUvq3bn0pyjCRaiRU6aDO+gb3aEfEeVNsDgm8zzLy9egPa7Qt8TSJdwhjplk06HH43ZNJ3s91KKCHQ5x4sw1fRGYDZ0n1L4FKb9/BP5JLYxToheoFCVxz57PPS8UhhEpLBVeAAAAAElFTkSuQmCC")
  }
}

user
|> Blvd.User.Schema.update_avatar(params)
|> Blvd.Repo.update!()

@darkbaby123
Copy link

Hello. I have the same requirement and check your way. But I can't pass %{filename: "x", binary: "y"} to cast_attachments. After checking the code I found the arc_ecto only support Plug.Upload struct. I still want to use arc_acto for versioning feature. But I don't want to create a Plug.Upload by saving the binary to a temp file. Can you tell me what should I do?

@anoskov
Copy link
Author

anoskov commented Dec 26, 2016

I think it broke on 0.5.0 version in this function: #107 (comment)
commit: stavro/arc_ecto@9719139
As can i see now arc_ecto can accept upload or file_path. You can use 0.4.3 version.
Or you can open issue and ask Stavro. Good luck!

@darkbaby123
Copy link

@anoskov Thanks, I created an issue under arc_ecto.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants