Class: Ecoportal::API::GraphQL::FileUpload::Client
- Inherits:
-
Object
- Object
- Ecoportal::API::GraphQL::FileUpload::Client
- Defined in:
- lib/ecoportal/api/graphql/file_upload/client.rb
Overview
Orchestrates the full file upload workflow:
Step 1 — Get S3 pre-signed credentials via GraphQL Step 2 — Upload file directly to S3 (multipart form POST) Step 3 — Register the upload with EcoPortal (REST POST /v2/s3/files) Step 4 — Poll until the FileContainer is created
Returns a fileContainerId string on success, suitable for use in DataField::FileField#file_container_ids= or DataField::ImageGallery#file_container_ids=
Usage: container_id = api.file_upload.upload('/path/to/report.pdf') page.components.get_by_name('Attachment').file_container_ids = [container_id] api.pages.update(page)
Requires the gem to have been initialised with email/pass (OAuth Bearer token).
Constant Summary collapse
- POLL_INTERVAL =
seconds between poll attempts
2- POLL_MAX_WAIT =
seconds before giving up
120
Instance Method Summary collapse
-
#initialize(graphql_client) ⇒ Client
constructor
A new instance of Client.
-
#upload(file_path) ⇒ Object
Upload a file and return the fileContainerId.
Constructor Details
#initialize(graphql_client) ⇒ Client
Returns a new instance of Client.
30 31 32 33 34 35 |
# File 'lib/ecoportal/api/graphql/file_upload/client.rb', line 30 def initialize(graphql_client) @graphql_client = graphql_client @http_client = graphql_client.client.http_client @org_id = @http_client.org_id @host = @http_client.host end |
Instance Method Details
#upload(file_path) ⇒ Object
Upload a file and return the fileContainerId. Raises RuntimeError on failure.
39 40 41 42 43 44 45 46 |
# File 'lib/ecoportal/api/graphql/file_upload/client.rb', line 39 def upload(file_path) raise ArgumentError, "File not found: #{file_path}" unless File.exist?(file_path) creds = fetch_s3_credentials s3_key = direct_upload_to_storage(file_path, creds) poll_id = register_upload(file_path, s3_key) poll_for_container_id(poll_id) end |