Docs Examples Storage → Queue → Function
Storage

Storage → Queue → Function

Upload files and process them asynchronously.

The Pattern

Storage Queue Function

Why this pattern?

  • Direct upload: Files go straight to storage, not through your server
  • Async processing: Large files don't block your API
  • Automatic retries: Queue ensures processing completes
  • Metadata tracking: Attach user IDs, types, and other context
Example implementation
// 1. Upload file directly (multipart: file + path)
const form = new FormData();
form.append('file', fileData);
form.append('path', 'uploads/report.csv');
const uploadRes = await fetch('https://api.rocketstack.dev/storage/objects', {
  method: 'POST',
  headers: { 'Authorization': 'Bearer YOUR_API_KEY' },
  body: form
});
const { data: { path } } = await uploadRes.json();

// 2. Enqueue processing job (use existing queue with function delivery)
await fetch(`https://api.rocketstack.dev/queues/${process.env.ROCKETSTACK_QUEUE_ID}/messages`, {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer YOUR_API_KEY',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    payload: { path, userId: 'usr_123' }
  })
});

// 3. Function processes the file
// fn_process_csv (deliveryTarget.functionId)
export default async function handler(event) {
  const { path, userId } = event.payload;

  // Get download URL
  const dlRes = await fetch('https://api.rocketstack.dev/storage/download-url', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer YOUR_API_KEY',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({ path })
  });
  const { data: { downloadUrl } } = await dlRes.json();

  // Download and process
  const file = await fetch(downloadUrl).then(r => r.text());
  const records = parseCSV(file);

  await importRecords(records, userId);

  return { imported: records.length };
}
Free tier available

Ready to start building?

Create your free account and integrate infrastructure primitives in minutes.