Module: FizzyApiClient::Resources::DirectUploads
- Included in:
- Client
- Defined in:
- lib/fizzy_api_client/resources/direct_uploads.rb
Instance Method Summary collapse
- #create_direct_upload(filename:, byte_size:, checksum:, content_type:, account_slug: nil) ⇒ Object
- #upload_file(file_path_or_io, filename: nil, content_type: nil, account_slug: nil) ⇒ Object
Instance Method Details
#create_direct_upload(filename:, byte_size:, checksum:, content_type:, account_slug: nil) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/fizzy_api_client/resources/direct_uploads.rb', line 6 def create_direct_upload(filename:, byte_size:, checksum:, content_type:, account_slug: nil) slug = effective_account_slug(account_slug) payload = { filename: filename, byte_size: byte_size, checksum: checksum, content_type: content_type } response = connection.post("/#{slug}/rails/active_storage/direct_uploads", body: { blob: payload }) response.body end |
#upload_file(file_path_or_io, filename: nil, content_type: nil, account_slug: nil) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/fizzy_api_client/resources/direct_uploads.rb', line 21 def upload_file(file_path_or_io, filename: nil, content_type: nil, account_slug: nil) file_content, file_name, file_size = read_file_info(file_path_or_io, filename) checksum = calculate_checksum(file_content) content_type ||= "application/octet-stream" # Step 1: Create direct upload result = create_direct_upload( filename: file_name, byte_size: file_size, checksum: checksum, content_type: content_type, account_slug: account_slug ) # Step 2: Upload to storage URL upload_url = result["direct_upload"]["url"] upload_headers = result["direct_upload"]["headers"] || {} put_to_external_url(upload_url, file_content, upload_headers) # Step 3: Return signed_id result["signed_id"] end |