elixir-samples
elixir-samples copied to clipboard
Timeout when trying to upload a file via a form
Hello,
i've got a little problem. I want to upload a file via a form to my google cloud bucket.
With the file_input function from the Phoenix.HTML.Form module i receive an upload plug like this:
%Plug.Upload{
content_type: "image/png",
filename: "2013_03_512x5124.png",
path: "/var/folders/rx/r_c4m3yj41n4s4gn_s843pm00000gn/T//plug-1543/multipart-1543267977-811873296929292-1"
}
I use the filename and the path as input for my upload function:
def upload_image(file_path, file_name) do
# Authenticate.
{:ok, token} = Goth.Token.for_scope("https://www.googleapis.com/auth/cloud-platform")
conn = GoogleApi.Storage.V1.Connection.new(token.token)
bucket_id = System.get_env("GOOGLE_PROJECT_ID")
file_uuid = UUID.uuid4(:hex)
unique_filename = "#{file_uuid}-#{file_name}"
# Make the API request.
GoogleApi.Storage.V1.Api.Objects.storage_objects_insert_simple(
conn,
bucket_id,
"multipart",
%{name: unique_filename},
image_binary
)
end
But when the upload_image function get's triggered, my application runs into a timeout.
The error from my test is also not very informative...
** (ExUnit.TimeoutError) test timed out after 60000ms. You can change the timeout:
1. per test by setting "@tag timeout: x"
2. per case by setting "@moduletag timeout: x"
3. globally via "ExUnit.start(timeout: x)" configuration
4. or set it to infinity per run by calling "mix test --trace"
(useful when using IEx.pry)
Timeouts are given as integers in milliseconds.
code: Erlebe.Uploader.Google.upload_image(
stacktrace:
(inets) httpc.erl:626: :httpc.handle_answer/3
(inets) httpc.erl:567: :httpc.handle_request/9
(tesla) lib/tesla/adapter/httpc.ex:32: Tesla.Adapter.Httpc.request/2
(tesla) lib/tesla/adapter/httpc.ex:19: Tesla.Adapter.Httpc.call/2
(tesla) lib/tesla/middleware/core.ex:6: Tesla.Middleware.Normalize.call/3
(google_api_storage) lib/google_api/storage/v1/api/objects.ex:559: GoogleApi.Storage.V1.Api.Objects.storage_objects_insert_simple/6
test/erlebe/uploader/google_test.exs:21: (test)
(ex_unit) lib/ex_unit/runner.ex:312: ExUnit.Runner.exec_test/1
(stdlib) timer.erl:166: :timer.tc/1
(ex_unit) lib/ex_unit/runner.ex:251: anonymous fn/4 in ExUnit.Runner.spawn_test/3
I really hope someone can help me with my issue!
Thanks in advance, Felix
I have the same issue. Did you find a fix @fklement ?
@kofron No until now i didn't find any fix.
I ended with using the arc backend for Google Cloud Storage.
https://github.com/martide/arc_gcs .
Works perfectly!!
Having the same problem with plug uploads