instance method
upload
Ruby on Rails 5.2.8.1
Since v5.2.8.1Signature
upload(io)
Uploads the io to the service on the key for this blob. Blobs are intended to be immutable, so you shouldn’t be using this method after a file has already been uploaded to fit with a blob. If you want to create a derivative blob, you should instead simply create a new blob based on the old one.
Prior to uploading, we compute the checksum, which is sent to the service for transit integrity validation. If the checksum does not match what the service receives, an exception will be raised. We also measure the size of the io and store that in byte_size on the blob record.
Normally, you do not have to call this method directly at all. Use the factory class methods of build_after_upload and create_after_upload!.
Parameters
-
ioreq
Source
# File activestorage/app/models/active_storage/blob.rb, line 153
def upload(io)
self.checksum = compute_checksum_in_chunks(io)
self.content_type = extract_content_type(io)
self.byte_size = io.size
self.identified = true
service.upload key, io, checksum: checksum, **service_metadata
end
Defined in activestorage/app/models/active_storage/blob.rb line 153
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveStorage::Blob