class method self.create_and_upload!

Ruby on Rails 8.1.3.1

Since v6.0.6.1

Available in: v6.0.6.1 v6.1.7.10 v7.0.10 v7.1.6 v7.2.3.2 v8.0.5.1 v8.1.3.1 edge

Signature

self.create_and_upload!(key: nil, io:, filename:, content_type: nil, metadata: nil, service_name: nil, identify: true, record: nil)

Creates a new blob instance and then uploads the contents of the given io to the service. The blob instance is going to be saved before the upload begins to prevent the upload clobbering another due to key collisions. When providing a content type, pass identify: false to bypass automatic content type inference.

The optional key parameter is treated as trusted. Using untrusted user input as the key may result in unexpected behavior.

Parameters

key key = nil
io keyreq
filename keyreq
content_type key = nil
metadata key = nil
service_name key = nil
identify key = true
record key = nil
Source
# File activestorage/app/models/active_storage/blob.rb, line 106
    def create_and_upload!(key: nil, io:, filename:, content_type: nil, metadata: nil, service_name: nil, identify: true, record: nil)
      create_after_unfurling!(key: key, io: io, filename: filename, content_type: content_type, metadata: metadata, service_name: service_name, identify: identify).tap do |blob|
        blob.upload_without_unfurling(io)
      end
    end

Defined in activestorage/app/models/active_storage/blob.rb line 106 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActiveStorage::Blob

Type at least 2 characters to search.

Use the arrow keys to navigate results, Enter to open one, Escape to close.

Keyboard shortcuts

/
Focus search
⌘K / Ctrl-K
Command palette
?
This help
Esc
Close