# controller
def id_doc
# Get the current card id
user_id = ForestLiana::ResourcesGetter.get_ids_from_request(params,'bug param').first
user = ::User.find(user_id)
# Get the values of the input fields entered by the admin user.
attrs = params.dig('data', 'attributes', 'values')
# id_file = attrs['Valid proof of ID'];
user.user_id_doc = attrs['Valid proof of ID']
user.save!
render json: { success: "Valid proof of ID uploaded" }
end
# action
action 'Id Doc',
type: 'single',
fields: [{
field: 'Valid proof of ID',
description: 'Local ID card or passport',
type: 'File',
widget: 'file picker',
is_required: true
}]
# console log
Started POST "/forest/actions/id-doc?timezone=America%2FNew_York" for 127.0.0.1 at 2021-12-22 12:47:45 -0500
Processing by Forest::UsersController#id_doc as JSON
Parameters: {"data"=>{"attributes"=>{"values"=>{"Valid proof of ID"=>"data:image/png;name=exp_catgs_2021-12-20.png;base64,iVBORw0KGgoAAAANSUhEUgAABRQAAAJ/CAIAAACGEMioAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH5QwUERMqN2ZMWwAAIABJREFUeNrs3XVYFPkfB/
....
User Update (0.6ms) UPDATE "users" SET "user_id_doc" = $1, "updated_at" = $2 WHERE "users"."id" = $3 [["user_id_doc", nil], ["updated_at", "2021-12-22 16:35:10.232741"], ["id", 1]]
Saves but the file is nil.
Edit:
Just wanted to add that I am able to upload images using the regular add/edit features.
Rails 6 app using Carrierwave to upload to AWS.
Could you please tell us a bit more about what you’re trying to achieve?
If the regular image uploader is working, why do you need to create a smart action exactly?
A user can upload their id document when signing up or do it later. There are a lot of fields on the sign up form, so we want to make it simple later on for admins to upload just the id document - just a one field upload doc smart action.
Does the above shown code have any errors - is that the correct way to create a file upload smart action, or is there a mistake there?
Just fyi - I have a receipts smart action also attempting to upload an image, same thing with it too - regular add/edit works, but smart action doesn’t, so I really don’t understand why add/edit works and smart actions don’t.
Happy to hear that! the behavior difference between add/create and smart action is pretty strange, but if it’s work, i’m satisfied.
Thank you for sharing the solution with us.
After thinking about it a bit more, and comparing the logs of an upload via a regular edit and then via smart action, I don’t know why the smart action upload fails and the edit one works either.