Open stochastic-thread opened 9 years ago
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!
Does this support using an http url instead of a file path to upload an image directly to s3?
@chowza I have a branch open which does this: https://github.com/stavro/arc/pull/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!
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.
@gordonbisnor Can I see your model and the changeset function you have defined?
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
@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.
@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
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/
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:
In my head a workflow would look something like:
I believe ExAws has all of the necessary logic to do this.
Does this support direct uploads to S3?