NewBee
Upload ,ecto ,elixir graphql
I have created my schema , my table expenses and all it contains an attribut document with type string , I want to use as a :upload and test it via graphiql
I did that in my mutation to create expense : .
arg(:file_upload, non_null(:upload))
resolve(fn args, _ ->
# this is a `%Plug.Upload{}` struct. A server (a GenServer specifically) that manages uploaded files.
args.file_upload
{:ok, "success"}
end)
I did a test in graphiql but it returns argument fileUpload an invalide Value
Most Liked
darkblueorange
Here is a quick (& dirty) implementation :
In schema
object :governance_mutations do
@desc "Upload a file"
field :upload_file, :string do
arg :file_data, non_null(:upload)
resolve(&Resolvers.GovernanceResolver.upload_file/2)
end
In resolver :
def upload_file(%{file_data: %Plug.Upload{content_type: _content, filename: orig_filename, path: path_to_filename} = _args}, _) do
Governances.upload_on_request_type(orig_filename, path_to_filename)
{:ok, "success"}
end
Then :
def upload_on_request_type(orig_filename, path_to_filename) do
case File.read(path_to_filename) do
{:ok, contents} ->
Logger.info("Reading file succeeded")
%RequestType{}
|> RequestType.changeset(%{name: "Photo", business_line_id: "1", file_data: contents})
|> Repo.insert()
{:ok, "Success"}
{:error, reason} ->
Logger.info("File reading error : #{inspect(reason)}")
{:error, reason}
end
end
We need to tell Postgres to accept binary stuff before (otherwise simply copy paste the file elsewhere is filesystemstorage is ok, or even sending it to any bucket).
Thank you @benwilson512 by the way for this really really awesome work 
2
Popular in Questions
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1]
15:22:35.803 [error] gen_event {lager_file_backend...
New
What is the idiomatic way of matching for not nil in Elixir?
E.g.,
First way:
defp halt_if_not_signed_in(conn, signed_in_account) when...
New
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
The Elixir Typespec docs show the following syntax for keyword lists in typespecs:
# ...
| [key: type] # keyword lis...
New
Background
Let’s assume I have a typical GenServer that receives messages as requests, does some operation in a DB and returns responses....
New
Hi all
I want to have a unix time, from the current time plus 1 hour.
DateTime.now + 1 hour
How to get it in elixir?
Thanks
New
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
I will often find my self writing things similar to:
case some_value do
nil -> something()
"" -> something()
_ -> someth...
New
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
I am trying to run a deploy with docker and I successfully runned with this command:
docker build -t romenigld/blog-prod .
but when I t...
New
Other popular topics
Hi! May someone helps me, please!
I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
Manning 2016 Halloween weekend sale via Deal of the Day
Friday, October 28 - Half off all MEAPs - code WM102816LT
Saturday, October 29 ...
New
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
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
Hi all,
Trying to get some more clarity over utc_datetime and naive_datetime for Ecto:
https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this:
...
New
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!)
This post collects co...
New
I have followed this StackOverflow post to install the specific version of Erlang.
And When I am running mix ecto.setup then getting fol...
New
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
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New







