Upload Library Tracks
Besides creating library tracks via the web app it is also possible to create them via the API. This is great for automating the process of analyzing audio files.
The process of creating the library tracks can be broken down into three simple steps:
- Requesting a file upload
- Uploading the file
- Create a library track from the file upload
#
Requesting a file uploadA link as well as a ID which is used for creating a library track from an file upload can be retrieved with the Mutation.fileUploadRequest
field.
A sample response might look like the following:
The response is important for the next two steps.
#
Uploading the fileThe result from the Mutation.fileUploadRequest
field contains a uploadUrl
which is the target where our file must be uploaded to.
The file must be uploaded via a PUT
HTTP request to that given uploadUrl
.
Example: Upload file via curl
Example: Upload file via fetch in Node.js
#
Creating the Library TrackAfter the file has been successfully uploaded, the id
value returned on the Mutation.fileUploadRequest
field can be used for creating the library track.
The Mutation.libraryTrackCreate
field returns a LibraryTrackCreateResult
GraphQL union type, which can either be a LibraryTrackCreateSuccess
or a LibraryTrackCreateError
.
#
Creation failedIn case an error occurred the code
field on the LibraryTrackCreateError
can be checked for the reason of the failed creation. A human readable message is also provided via the message
field.
#
Example response#
Error code overviewError code | Meaning |
---|---|
fileUploadNotFound | Step two, uploading the file, has either been skipped or failed. |
invalidUploadId | The upload id does not belong to any requested file upload. |
librarySizeLimitExceededError | The basic account tier has a library size limitation of 30. Any attempt to create more LibraryTracks after exceeding that limit will result in this error code. |
#
Creation succeededThe Mutation.libraryTrackCreate
field returns a LibraryTrackCreateSuccess
result, the creation of the library track succeeded.
It is possible to immediately query for the id
(as well as other data) of the created track via the createdLibraryTrack
field.
This is useful for storing the id mapping from another database to the Cyanite.ai library track.
The track is also automatically enqueued for all eligible analysis types for the given account.
The enqueue result can be selected via the enqueueResult
field on the LibraryTrackCreateSuccess
type.
In case the account exceeded the analysis limit, the track will not be enqueued and it must be enqueued at a later point using the Mutation.libraryTrackEnqueue
field.