-
Notifications
You must be signed in to change notification settings - Fork 101
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
Upload a file from an IO object #82
Comments
My current solution is the following monkey patch: module Boxr
class Client
def upload_file_from_io(io, parent, name:, content_created_at: nil, content_modified_at: nil, preflight_check: true, send_content_md5: true)
parent_id = ensure_id(parent)
# TODO: the preflight check reads files from disk, so we can't use it right now
# preflight_check(path_to_file, name, parent_id) if preflight_check
if send_content_md5
content_md5 = Digest::SHA1.hexdigest(io.read)
io.rewind
end
attributes = {name: name, parent: {id: parent_id}}
attributes[:content_created_at] = content_created_at.to_datetime.rfc3339 unless content_created_at.nil?
attributes[:content_modified_at] = content_modified_at.to_datetime.rfc3339 unless content_modified_at.nil?
body = {attributes: JSON.dump(attributes), file: io}
file_info, response = post(FILES_UPLOAD_URI, body, process_body: false, content_md5: content_md5)
file_info.entries[0]
end
end
end I think this could also be merged to the project. If you are interested, I can create a PR. |
Hey @moonglum , thanks for writing in! Sorry for the late reply. This has been a huge pain point for myself as well in my company's implementation, so I would love to see this enhancement. Would you please open a PR? Thanks! 🙏 |
No problem 👍 I'll get a PR ready. I'm using it in a Rails 6 app with ActiveStorage. I can also open source the Box ActiveStorage adapter I wrote after testing it for a little while. |
@moonglum That sounds amazing! I had checked and was sad to see no open-source Box adapter for ActiveStorage, which probably blocks adoption for some people. I'd be happy to help you maintain that if you need any help! |
@xhocquet Pull Request is ready now 👍 Great! I'll get back to you when the adapter is ready for someone else but me 😄 |
Resolved with #83! 🎉 |
Awesome, thanks 🎺 |
Is your feature request related to a problem? Please describe.
I want to be able to upload files to Box without first writing them to Disk. For example data uploaded to a Rails App.
Describe the solution you'd like
The current
upload_file
method always expects a filename, I would instead just provide the data.Describe alternatives you've considered
I don't really know an alternative except writing the file to disk first.
Additional context
Thanks for the Ruby Gem 🙇
The text was updated successfully, but these errors were encountered: