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

Timeout when trying to upload a file via a form #24

Open
fklement opened this issue Nov 26, 2018 · 3 comments
Open

Timeout when trying to upload a file via a form #24

fklement opened this issue Nov 26, 2018 · 3 comments

Comments

@fklement
Copy link

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

@kofron
Copy link

kofron commented Dec 12, 2018

I have the same issue. Did you find a fix @fklement ?

@fklement
Copy link
Author

@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!!

@mrkaspa
Copy link

mrkaspa commented Jun 28, 2020

Having the same problem with plug uploads

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

No branches or pull requests

5 participants