m365-active-storage
Rails ActiveStorage in M365 Sharepoint
Install the gem
gem install m365_active_storageor add to the Gemfile:
gem "m365_active_storage"Configure ActiveStorage
Configure Active Storage and auth
Rails credentials
sharepoint:
ms_graph_url:
ms_graph_version:
auth_host:
oauth_tenant:
oauth_app_id:
oauth_secret:
sharepoint_site_id:
sharepoint_drive_id:-- or --
ENV
MS_GRAPH_URL=
MS_GRAPH_VERSION=
AUTH_HOST=
OAUTH_TENANT=
OAUTH_APP_ID=
OAUTH_SECRET=
SHAREPOINT_SITE_ID=
SHAREPOINT_DRIVE_ID=Set active storage to sharepoint service
In the app config/environments/<environment>.rb
config.active_storage.service = :sharepointRun the check generator
$ rails g m365_active_storage:check
Move files from local to sharepoint with the migrate generator
g m365_active_storage:migrate5 blobs to migrate
filename_1 done
filename_2 done
filename_3 done
filename_4 failed: ActiveStorage::FileNotFoundError
filename_5 done
...Note
The local files are still in the storage folder.
You must delete them manually after validating the data has been correctly moved.
Note
Don't forget to restart your server, if running