Files
docuseal/app/controllers/api/attachments_controller.rb
T

29 lines
834 B
Ruby
Raw Normal View History

2023-05-21 17:59:36 +03:00
# frozen_string_literal: true
module Api
class AttachmentsController < ApiBaseController
skip_before_action :authenticate_user!
def create
2023-06-18 16:30:35 +03:00
submitter = Submitter.find_by!(slug: params[:submitter_slug])
2023-05-28 23:20:48 +03:00
blob =
if (file = params[:file])
ActiveStorage::Blob.create_and_upload!(io: file.open,
filename: file.original_filename,
content_type: file.content_type)
else
ActiveStorage::Blob.find_signed(params[:blob_signed_id])
end
2023-05-21 17:59:36 +03:00
attachment = ActiveStorage::Attachment.create!(
blob:,
name: params[:name],
2023-06-24 12:27:34 +03:00
record: submitter
2023-05-21 17:59:36 +03:00
)
render json: attachment.as_json(only: %i[uuid], methods: %i[url filename content_type])
end
end
end