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

Feature request: Direct Uploads Support #529

Open
hwhelchel opened this issue Apr 20, 2019 · 4 comments
Open

Feature request: Direct Uploads Support #529

hwhelchel opened this issue Apr 20, 2019 · 4 comments

Comments

@hwhelchel
Copy link

Active Storage lets you upload files from the client directly to the cloud by setting direct_upload: true on your file_field in the form.

Would be awesome if Bootstrap Form automatically hooked into this feature and showed a visual progress bar of the file uploading using standard Bootstrap components.

https://edgeguides.rubyonrails.org/active_storage_overview.html#direct-uploads

@lcreid
Copy link
Contributor

lcreid commented Apr 20, 2019

That's a great suggestion. We're very open to a pull request to provide this feature. Personally I'm a little busy right now, but if no one else picks it up in the next few months I'll take a look.

@hwhelchel
Copy link
Author

@lcreid awesome thanks!

@Bodata
Copy link

Bodata commented Oct 29, 2020

A workaround regarding the problem:

I did not get any progressbar when using bootstrap_form_for. When i changed back to a form_for this worked.
In order to get it to work i had to remove the label added by bootstrap_form. (a poormans option)

I made this work bij changing the direct-upload:initialize code

'addEventListener("direct-upload:initialize", event => {
  const { target, detail } = event
  const { id, file } = detail
  target.insertAdjacentHTML("beforebegin",
  ......
  )
  target.previousElementSibling.querySelector(`.direct-upload__filename`).textContent = file.name
})

and changed it into

'addEventListener("direct-upload:initialize", event => {
  const { target, detail } = event
  const { id, file } = detail
  var custom_file_labels = document.getElementsByClassName("custom-file-label");
  while (custom_file_labels[0]) {
    custom_file_labels[0].parentNode.removeChild(custom_file_labels[0])
  }
  target.insertAdjacentHTML("beforebegin",
  ......
  )
  target.previousElementSibling.querySelector(`.direct-upload__filename`).textContent = file.name
})

Hope this works for others too.

@lcreid
Copy link
Contributor

lcreid commented Jan 14, 2021

A very belated, but very big, thanks for your suggestion. We'll look at how we can incorporate this into the gem. Feel free to send us a pull request if you think you have an idea for how we could do it.

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

3 participants