Skip to main content

Uploading files

To support uploading files to EventsAir, the API exposes a separate, dedicated endpoint. This page contains the necessary information to take advantage of it.

Overview

The GraphQL specification does not define how file uploads should be handled and there is no standard implementation across GraphQL servers and clients. To ensure compatibility with the broadest range of client applications a separate API endpoint was created to handle file uploads:

https://api.eventsair.com/file

This implies that uploading files to EventsAir is a multi-step process:

  1. Upload the file through the endpoint mentioned above, whose response will contain a temporary file identifier.
  2. Use the temporary file identifier in a GraphQL mutation.

Request

The server expects a request with the following attributes:

  • It must be authenticated like GraphQL requests, see the "Get an access token" guide for more information.
  • The Content-Type header must be set to multipart/form-data.
  • The body must contain a single part named file which contains the file contents.
  • By default, files uploaded to EventsAir are limited to 15 MB in size.

Requests that don't comply with these requirements will not be processed.

Here are some examples to issue such a request.

internal class Program
{
static async Task Main(string[] args)
{
var httpClient = new HttpClient
{
BaseAddress = new Uri("https://api.eventsair.com"),
};

var accessToken = "<access-token>";
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);

var filePath = "<path-to-file>";
var content = new MultipartFormDataContent
{
{ new StreamContent(File.OpenRead(filePath)), "file", Path.GetFileName(filePath) }
};

var response = await httpClient.PostAsync("/file", content);
var data = await response.Content.ReadFromJsonAsync<FileUploadResponse>();
Console.WriteLine(data.TemporaryFileId);
}
}

internal class FileUploadResponse
{
public Guid TemporaryFileId { get; set; }
}