Skip to main content

Uploads


The Uploads API provides methods for uploading audio and image files to Audius storage nodes. These methods return CIDs (Content Identifiers) that you then pass to write methods like createTrack or updateTrack.

tip

File uploads are a separate step from track/playlist creation. You first upload your files using the Uploads API to get CIDs, then pass those CIDs as metadata when creating or updating content.


createAudioUpload

createAudioUpload(params)

Upload an audio file to a storage node. Returns the resulting CIDs and audio analysis metadata (duration, BPM, musical key).

Create an object with the following fields and pass it as the first argument.

NameTypeDescriptionRequired?
fileFileThe audio file to uploadRequired
onProgress(loaded: number, total: number) => voidA callback for tracking upload progressOptional
previewStartSecondsnumberStart time in seconds for generating a preview clipOptional
placementHostsstring[]A list of storage node hosts to prefer for placementOptional

createImageUpload

createImageUpload(params)

Upload an image file (e.g. cover art or profile picture) to a storage node. Returns the resulting CID.

Create an object with the following fields and pass it as the first argument.

NameTypeDescriptionRequired?
fileFileThe image file to uploadRequired
onProgress(loaded: number, total: number) => voidA callback for tracking upload progressOptional
isBackdropbooleanSet to true for wide/banner images (e.g. profile banners). Default: falseOptional
placementHostsstring[]A list of storage node hosts to prefer for placementOptional

Full Example: Upload and Create a Track

This example demonstrates the full workflow of uploading files via the Uploads API and then creating a track with the returned CIDs.

import fs from 'fs'

// Step 1: Upload the audio file
const trackBuffer = fs.readFileSync('path/to/track.mp3')
const audioUpload = audiusSdk.uploads.createAudioUpload({
file: {
buffer: Buffer.from(trackBuffer),
name: 'track.mp3',
type: 'audio/mpeg',
},
previewStartSeconds: 30,
})
const audioResult = await audioUpload.start()

// Step 2: Upload cover art
const coverArtBuffer = fs.readFileSync('path/to/cover-art.png')
const imageUpload = audiusSdk.uploads.createImageUpload({
file: {
buffer: Buffer.from(coverArtBuffer),
name: 'cover-art.png',
type: 'image/png',
},
})
const coverArtCid = await imageUpload.start()

// Step 3: Create the track using the CIDs from the uploads.
// The audio upload result fields (trackCid, previewCid, origFileCid, etc.)
// match the metadata field names, so you can spread them directly.
const { data } = await audiusSdk.tracks.createTrack({
userId: '7eP5n',
metadata: {
title: 'Monstera',
description: 'Dedicated to my favorite plant',
genre: 'Metal',
mood: 'Aggressive',
...audioResult,
coverArtCid: coverArtCid,
},
})