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

Direct uploads? #1

Open
stochastic-thread opened this issue Jun 18, 2015 · 10 comments
Open

Direct uploads? #1

stochastic-thread opened this issue Jun 18, 2015 · 10 comments

Comments

@stochastic-thread
Copy link

Does this support direct uploads to S3?

@stavro
Copy link
Owner

stavro commented Jun 19, 2015

I assume you mean "Browser Uploads to S3" directly (rather than going through your webserver), as outlined here.

Right now arc does not facilitate this.

Let me think a bit about how an integration might look and if including it in this package vs a separate package would be best.

Thanks for your input!

@terencechow
Copy link

Does this support using an http url instead of a file path to upload an image directly to s3?

@stavro
Copy link
Owner

stavro commented Oct 14, 2015

@Chowza I have a branch open which does this: #7

I haven't merged it since I'm not actually using it in production yet, and I might want to change it to be a little more explicit about remote vs. local retrieval. But you're welcome to try it and let me know your thoughts!

@gordonbisnor
Copy link

Do you think the remote-files branch work with arc_ecto? Anything special required to make it work?

I am attempting to build a seed file... in mix.exs I have:

{:arc, git: "https://github.com/stavro/arc.git", branch: "remote-files", override: true},

And in my seed file:

path = ~s(http://www.isnorcreative.com/system/images/#{image.id}/original/#{image.file})
changeset = Gbiphoenix.ProjectImage.changeset(%Gbiphoenix.ProjectImage{}, %{project_id: project.id, image: path} )
Gbiphoenix.Repo.insert!(changeset)

I am getting a changeset error:

[image: "can't be blank"]

I have been looking poking around in arc and arc_ecto seeing if arc_ecto would need to be modified to make this work, but have yet to figure it out.

@stavro
Copy link
Owner

stavro commented Oct 29, 2015

@gordonbisnor Can I see your model and the changeset function you have defined?

@gordonbisnor
Copy link

Yes this is it here:

defmodule Gbiphoenix.ProjectImage do
  use Gbiphoenix.Web, :model
  use Arc.Ecto.Model

  schema "project_images" do
    field :image, Gbiphoenix.Image.Type
    belongs_to :project, Gbiphoenix.Project
    timestamps
  end

  @required_fields ~w(project_id)
  @optional_fields ~w()

  @required_file_fields ~w(image)
  @optional_file_fields ~w()

  @doc """
  Creates a changeset based on the `model` and `params`.

  If no params are provided, an invalid changeset is returned
  with no validation performed.
  """
  def changeset(model, params \\ :empty) do
    model
    |> cast(params, @required_fields, @optional_fields)
    |> cast_attachments(params, @required_file_fields, @optional_file_fields)
  end
end

@gordonbisnor
Copy link

@stavro It seems that my seed file is specifying params with atom keys rather than string keys, which then causes the Dict.take function to return empty as it is comparing the binary lists of ~w() optional_file_fields and required_file_fields with the atoms of my seed file params.

I have an arc-ecto fork with a remote-files branch where I convert the required ++ optional list to atoms which worked for me. I didn't do a pull request because I don't know exactly what's going on here – I'm new to Elixir. I also found that I needed to convert the maps in the model test file to use atom keys as well, I was getting 4 failing tests with string keys.

Now that I think of it, I must have created the broken tests in my fork by converting the keys to atoms.

@Lazarus404
Copy link

@stavro did you get the uploads pass-thru working? Is this a feature yet of Arc? If not, did you create a separate package providing this? I'd like to facilitate pass-thru upload and download of files.

Thanks

@simonh1000
Copy link

simonh1000 commented Jun 30, 2016

Me too for pass-through - what is the status. It looks as the S3 libraries come with some sort of signing function (e.g. for node) which needs to be emulated? This code might already do it http://jhosteny.github.io/2015/06/10/elixir-clojurescript-s3-upload/

@stavro
Copy link
Owner

stavro commented Jun 30, 2016

I have not started on this feature, and I likely won't have time to for a little while.

But I am open to including some of the core functionality in this package.

Namely:

  • A straightforward way of generating the policy, signature, etc.
  • A way to consume the uploaded file and run transformations.

In my head a workflow would look something like:

  1. Server creates an upload form using policy, signature, etc from Arc.
  2. Client uploads file directly to S3.
  3. Upon successful upload, client informs server that the upload has finished.
  4. Server instructs Arc to process transformations of the newly uploaded file.

I believe ExAws has all of the necessary logic to do this.

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

6 participants