Skip to content

rafaelrubbioli/fileapi

Repository files navigation

Report card License MIT Actions Status

Note

I'm no longer maintaining the live version, but it is possible to run it yourself.

File API

This is a graphql api to upload and retrieve files on cloud storage (only s3 supported for now)

Some examples of queries/mutations on graphqlexplorer

Usage

Upload

To upload files use form-files as shown.

curl -X POST -i https://rubbioli.com/fileapi/graphql \
-F operations='{"query":"mutation($file: Upload!) {  upload(input:{ file: $file   user: 1    path: \"nginx/test/\"  }){    id  }}","variables": { "file": null } }' \  
-F map='{ "0": ["variables.file"] }' \
-F 0=@test.txt

Upload takes a user, and a path to upload the file to. overwrite is an optional input to decide if files uploaded to the same user and path should replace existing ones or return error.

Get

Get takes an id and returns the corresponding file entity. The id is a unique string given to every file after the upload.

query get {
  file(id: "") {
    id
    name
    path
    user
    fileType
    size
    createdAt
    updatedAt
    downloadURL
  }
}

Delete

Delete takes the file id and removes it from the storage permanently.

mutation delete {
  delete(id: "")
}

Move

Move takes the file id and a newPath and moves it, returning the resulting file. overwrite is an optional input to decide if files uploaded to the same user and path should replace existing ones or return error.

mutation move {
  move(input: {id: "", user: 0, newPath: "test/acl/file.txt"}) {
    id
  }
}

List files

List takes and user and a path prefix (optional) and returns the list of al user files under that path.

query list {
  listUserFiles(user: 1) {
    id
    name
    path
    user
    fileType
    size
    updatedAt
    downloadURL
  }
}

Roadmap

  • Parse s3 custom errors (such as not found, bad request)
  • List file tree
  • cmd/worker to process jobs asynchronously with retry (such as deleting a file)
  • Unit tests for service
  • Unit tests for graphql resolver

About

File storage GraphQL API

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages