Skip to content
  • Jonathan Hefner's avatar
    6aa26c30
    Identify directly-uploaded blobs before saving the associated record · 6aa26c30
    Jonathan Hefner authored
    An Active Storage `Blob` must be identified before it can be reliably
    validated.  For direct uploads, a `Blob` is identified when it is
    attached, rather than when it is created.
    
    Before this commit, the sequence of events when attaching a `Blob` was:
    
    1. Find the `Blob`.
    2. Assign the `Blob` to an `Attachment`.
    3. Save the owner record.
    4. Save the `Attachment`.
    5. Identify the `Blob`'s true `content_type` from its file.
    6. Save the `Blob`.
    
    This meant that the owner record's validations might not see the
    `Blob`'s true `content_type`.
    
    After this commit, the sequence of events will be:
    
    1. Find the `Blob`.
    2. Identify the `Blob`'s true `content_type` from its file.
    3. Assign the `Blob` to an `Attachment`.
    4. Save the owner record.
    5. Save the `Attachment`.
    6. Save the `Blob`.
    
    Thus the `Blob`'s true `content_type` will be available when running the
    owner record's validations.
    6aa26c30
    Identify directly-uploaded blobs before saving the associated record
    Jonathan Hefner authored
    An Active Storage `Blob` must be identified before it can be reliably
    validated.  For direct uploads, a `Blob` is identified when it is
    attached, rather than when it is created.
    
    Before this commit, the sequence of events when attaching a `Blob` was:
    
    1. Find the `Blob`.
    2. Assign the `Blob` to an `Attachment`.
    3. Save the owner record.
    4. Save the `Attachment`.
    5. Identify the `Blob`'s true `content_type` from its file.
    6. Save the `Blob`.
    
    This meant that the owner record's validations might not see the
    `Blob`'s true `content_type`.
    
    After this commit, the sequence of events will be:
    
    1. Find the `Blob`.
    2. Identify the `Blob`'s true `content_type` from its file.
    3. Assign the `Blob` to an `Attachment`.
    4. Save the owner record.
    5. Save the `Attachment`.
    6. Save the `Blob`.
    
    Thus the `Blob`'s true `content_type` will be available when running the
    owner record's validations.
Loading