Configuration

Global configuration is performed by calling methods on the Files object.

Configuration Options

Base URL

Set this to the full https:// URL of your Files.com subdomain (e.g. https://MY-SUBDOMAIN.files.com). This is not required in most cases, but one benefit of setting it is that it ensures that authentication failures will be logged to your site's API logs. Without setting this, we won't know which site to associate the authentication failure with, and it won't be logged to your site's API logs. This is always required if your site is configured to disable global acceleration. This can also be set to use a mock server in development or CI.

Example setting

import Files from 'files.com/lib/Files.js';

Files.setBaseUrl("https://MY-SUBDOMAIN.files.com");

Log Level

Supported values:

  • LogLevel.NONE
  • LogLevel.ERROR
  • LogLevel.WARN
  • LogLevel.INFO (default)
  • LogLevel.DEBUG

Example setting

import Files from 'files.com/lib/Files.js';
import { LogLevel } from 'files.com/lib/Logger.js';

Files.setLogLevel(LogLevel.INFO);

Debugging

Enable debug logging of API requests and/or response headers. Both settings default to false.

Example setting

import Files from 'files.com/lib/Files.js';

Files.configureDebugging({
  debugRequest: true,
  debugResponseHeaders: true,
});

Network Settings

networkTimeout (in seconds, 110 by default) limits each attempt of a request as one budget, from sending it until its response body has been read to its end; 0 or less sets no limit. An attempt that runs out of time before its response arrives is retried like a network failure, up to maxNetworkRetries, and one whose body stops arriving fails with a "Request timed out" FilesError. Each retry has a budget of its own, and the wait between attempts counts toward none. Nothing limits a call as a whole: give it a signal in its options, such as AbortSignal.timeout(milliseconds), for that.

Aborting a call's signal stops its requests at once, a wait before a retry included, and starts no further attempt. The call rejects with the signal's reason, unchanged, or, when the runtime gives none, an Error named AbortError.

A body that a call returns unread, as a stream, stays within its attempt until it has been read to its end: if the budget runs out, or the signal is aborted, before then, the call has already resolved, so the stream is stopped and fails with an error instead.

Example setting

import Files from 'files.com/lib/Files.js';

Files.configureNetwork({
  // max retries (default: 3)
  maxNetworkRetries: 3,

  // minimum delay in seconds before retrying (default: 0.1)
  minNetworkRetryDelay: 0.1,

  // max delay in seconds before retrying (default: 1.5)
  maxNetworkRetryDelay: 1.5,

  // network timeout in seconds (default: 110.0)
  networkTimeout: 110.0,

  // auto-fetch all pages when results span multiple pages (default: `true`)
  autoPaginate: true,
});