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)
Step 1 (GraphQL) authenticates via the gem's email/pass OAuth bearer token.
Steps 3-4 (REST v2 /s3/files) require the gem to ALSO have been initialised
with api_key: — Ecoportal::API::GraphQL.new(email:, pass:, api_key:) — since
those endpoints authenticate via X-ECOPORTAL-API-KEY, not the GraphQL bearer
token (mirrors Ecoportal::API::Common::Content::Client#base_request in
ecoportal-api-v2).
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.
35 36 37 38 39 40 |
# File 'lib/ecoportal/api/graphql/file_upload/client.rb', line 35 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.
44 45 46 47 48 49 50 51 |
# File 'lib/ecoportal/api/graphql/file_upload/client.rb', line 44 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 |