Active Storage Rails 6 API unable to insert to active_storage_attachments table
I am creating API endpoint for active storage with reactjs. My upload controller is as follows:
The code belows execute:
insert blob object in active_storage_blob - ok
Uploaded file to the designated path in storage - ok
Issue:
does not insert active_storage_attachments (polymorphic relation) I already add has_one_attached :photo
class Api::V1::Activestorage::DirectUploadsController < ActiveStorage::DirectUploadsController
skip_before_action :verify_authenticity_token
def create
blob = ActiveStorage::Blob.create_before_direct_upload!(blob_args)
render json: direct_upload_json(blob)
end
private
def blob_args
params.require(:blob).permit(:filename, :byte_size, :checksum, :content_type, metadata: {}).to_h.symbolize_keys
end
def direct_upload_json(blob)
blob.as_json(root: false, methods: :signed_id).merge(direct_upload: {
url: blob.service_url_for_direct_upload,
headers: blob.service_headers_for_direct_upload
})
end
end
Hope anyone can help me thanks