Filestore API Reference

Create file

POST filestore.<cluster-name>.hasura-app.io/v1/file/<file_id>

The POST endpoint lets you upload files.

You are required to generate a unique file_id for the file, and then send the file contents in the request body and setting the Content-Type header set to the file’s MIME type.

A typical request is as follows:

Request

POST filestore.<cluster-name>.hasura-app.io/v1/file/05c40f1e-cdaf-4e29-8976-38c899 HTTP/1.1
Content-Type: image/png

<contents of the file>

Response

An example response looks like:

HTTP/1.1 200 OK
Content-Type: application/json

{
  "file_id": "05c40f1e-cdaf-4e29-8976-38c899",
  "content_type": "image/png",
  "file_status": "uploaded",
  "file_size": 351667,
  "user_id": 42,
  "user_role": "user",
  "created_at": "2017-04-25T08:26:22.834266+00:00"
}

Upsert file

PUT filestore.<cluster-name>.hasura-app.io/v1/file/<file_id>

The PUT endpoint lets you update existing file or create a file.

the file contents in the request body and setting the Content-Type header set to the file’s MIME type.

A typical request is as follows:

Request

PUT filestore.<cluster-name>.hasura-app.io/v1/file/05c40f1e-cdaf-4e29-8976-38c899 HTTP/1.1
Content-Type: image/png

<contents of the file>

Response

An example response looks like:

HTTP/1.1 200 OK
Content-Type: application/json

{
  "file_id": "05c40f1e-cdaf-4e29-8976-38c899",
  "content_type": "image/png",
  "file_status": "uploaded",
  "file_size": 351667,
  "user_id": 42,
  "user_role": "user",
  "created_at": "2017-04-25T08:26:22.834266+00:00"
}

Retrieve file

GET /v1/file/<file_id>

This endpoint can be used to download the files. The files are streamed to the client.

Request

An example request would look like:

GET filestore.<cluster-name>.hasura-app.io/v1/file/05c40f1e-cdaf-4e29-8976-38c899 HTTP/1.1

Response

The file is streamed to the client with the Content-Type header set to the file’s MIME type.

Delete file

DELETE /v1/file/<file_id>

This endpoint can be used to delete the files. The files are streamed to the client.

Request

An example request would look like:

DELETE filestore.<cluster-name>.hasura-app.io/v1/file/05c40f1e-cdaf-4e29-8976-38c899 HTTP/1.1

Response

An example response looks like:

HTTP/1.1 200 OK
Content-Type: application/json

{
  "file_id": "05c40f1e-cdaf-4e29-8976-38c899",
  "status": "deleted"
}

Response structure

Status code Description Response structure
200 Success
Request specific
400 Bad request
{
    "code"  : String,
    "message" : String
}
401 Unauthorized
{
    "code" : String,
    "message" : String
}
500 Internal server error
{
    "code" : String,
    "message" : String
}

Error Codes

Status Code Code Message Description
400 bad_request missing header: <header-name> when expected header is not found in the request
400 bad_request missing parameter: <parameter-name> when expected parameter is not found in the request
400 bad_request X-Hasura-User-Id should be an integer X-Hasura-User-Id’ header value should be an integer
400 bad_request expected one and atmost one byte range in the header  
400 bad_request failed to parse range/x-hasura-filestore-range header  
400 bad_request range not satisfiable  
400 bad_request file already exists : <file-id> when user trying to write a file with existing file_id
403 access_denied no permission for role <role-name> when user is not allowed to p
403 access_denied access denied when configured filestore hook does not allow user to perform action
404 not_found file not found : <file-id> when user tries to read the file that does not exist
500 fatal_internal_error internal server error when user tries to fetch file info, when file not exists in filesystem, unexpected status from filestore hook