Dondon Abesamis

Joined

150 Experience
1 Lesson Completed
0 Questions Solved

Activity

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

logo Created with Sketch.

Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more. Icons by Icons8

© 2022 GoRails, LLC. All rights reserved.