Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Add JavaScript direct upload support #81

Merged
merged 1 commit into from Jul 27, 2017
Merged

Add JavaScript direct upload support #81

merged 1 commit into from Jul 27, 2017

Conversation

javan
Copy link
Contributor

@javan javan commented Jul 27, 2017

πŸ–₯ β†’ ☁️

Fixes #29
Probably fixes #79
Closes #35

def active_storage_meta_tags
safe_join [
tag.meta(name: 'direct-uploads-url', content: rails_direct_uploads_url)
]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's only one tag?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I'm thinking that maybe we should just decorate the specific file input tag with the URL instead. Like we do with other data-url decorations. We'll wrap that into a direct_upload_file_tag anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, yes. Leaves us open to adding more without introducing a name change like csrf_meta_tags.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's supported currently and will take precedence over the the meta tag value.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the meta tag is just there to save repeating the URL on the input tags? That seems like a bit of an over-optimization to me. I'd rather just have it on the input tag alone, such that using this feature doesn't require any setup gymnastics.

@javan
Copy link
Contributor Author

javan commented Jul 27, 2017

Demo / example using these direct upload events: https://gist.github.com/javan/5538692cb37a683db15792be8d05761e

@isaac
Copy link

isaac commented Jul 27, 2017

@javan looks great! Is there a way to start the upload as soon as the user selects the file(s) rather than when the form is submitted?

@dhh dhh merged commit 6262891 into rails:master Jul 27, 2017
@javan
Copy link
Contributor Author

javan commented Jul 28, 2017

@isaac not currently, but you can implement that yourself by handling a file input's change event and creating DirectUploads for its Files. See DirectUploadController for example usage.

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

Successfully merging this pull request may close these issues.

Get more informations on direct_uploads Add direct upload file_field using JavaScript
3 participants