Skip to content

Conversation

@jdalt
Copy link

@jdalt jdalt commented Jul 11, 2019

Feature

This PR allows a library user to return the entire response from /rails/active_storage/direct_uploads in the DirectUploaderProvider onSuccess callback when fullAttributes flag is set on the DirectUploadProvider.

Example

<DirectUploadProvider
  ...
  fullAttributes={ true }
  onSuccess={(signedFiles) => {
    console.log(signedFiles)
  }}
  ...
/>     

will log out the full payload returned by the rails active storage endpoint as:

[
  {
    id: 183,
    key: "L3kN4RRdsCFFQuiDwd82J39Z",
    filename: "DJI_0058.JPG",
    content_type: "image/jpeg",
    metadata: {}, 
    signed_id: "eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBBYmM9IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--f33fda912f4b4baa72c405efb385352dcf11ad92"
  }
]

Rationale

I understand that often times the signedId is all you need to make an attachment. It is sufficient for most cases. However when multiple files are uploaded, the exact file plus other data data is often needed to create or update records. In this case knowing which particular file the resulting AS upload result refers to is impossible with just the signedId and extra contextual information is necessary. By returning the entire payload of the newly created ActiveStorage::Blob record, the library user can tie the upload results to specific files.

Obviously this is only an issue when multiple files are uploaded and the attachments are not being made all to the same object, but that happens to just the problem I personally have ;).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant