I am attempting to build the elements needed to integrate with Filestack. I've written a very basic Storage plugin that uses the filestack-ruby gem to handle its operations. The bit I am less sure about is the best way to handle saving files.
We use Filestack.js in the frontend to save directly to Filestack. Then a metadata chunk of JSON can be passed down as part of saving the form. So far to save this to the model, I'm trying this:
I have a permanent store setup thus, with no cache:
Shrine.storages = {
# cache: Shrine::Storage::Filestack.new(**filestack_options),
store: Shrine::Storage::Filestack.new(**filestack_options),
}
Then to save a file to a model, am doing:
# Metadata is JSON data Filestack returns from saving a file
metadata = JSON.parse(metadata)
image_data = {
id: metadata['handle'], # Filestack captures an ID for the file in a "handle" field
storage: 'store',
metadata: metadata
}
image_data = JSON.dump(image_data)
attacher = ImageUploader::Attacher.new(post, :image)
uploaded_file = Shrine.uploaded_file(image_data)
attacher.set(uploaded_file)
This seems to save the data to the field, is this the right kind of approach for Filestack where it saves from client-side and returns a full metadata blob?
Any tips much appreciated!