viaSocket Help
DocStarBuilt with DocStar

File Upload using URL (for all file types)

When working with files like audio, images, videos, PDFs, or documents in your workflows, you often need to fetch them from a URL and upload them via an API. Since direct binary data isn’t always supported in APIs, viaSocket uses a standard approach: fetch → convert to base64 → send as JSON.


Why Base64?

APIs commonly accept base64-encoded files instead of raw binaries. This allows files to be:

  • Embedded in JSON payloads

  • Easily transmitted across APIs

  • Supported in actions like transcription, classification, extraction, and more


Supported File Types

This approach works for:

  • 🎧 Audio – MP3, WAV, OGG

  • 🖼️ Images – PNG, JPG, GIF

  • 🎬 Videos – MP4, MOV, AVI

  • 📄 PDFs

  • 📁 Documents – DOCX, XLSX, PPTX

  • 📦 Archives – ZIP, RAR

  • 🧠 Other binaries – firmware, installers


How It Works (in 4 steps)

1. Fetch File from URL

Use Axios to download the file in binary format:

const fileResponse = await axios.get(fileUrl, { responseType: 'arraybuffer' }); 

2. Convert File to Base64

Convert the binary data to base64:

const base64File = Buffer.from(fileResponse.data).toString('base64'); 

3. Prepare API Payload

Wrap the base64 in your request payload:

const payload = { data: base64File }; 

4. Send File to API

Send the payload to the API endpoint:

const apiResponse = await axios.post('https://api.example.com/v1/upload', payload, {   headers: {     'Authorization': 'Bearer YOUR_API_KEY',     'Content-Type': 'application/json',   }, }); 

Use Case: Audio Upload for Transcription (ChatGPT)

const audioUrl = context?.inputData?.url; const audioResponse = await axios.get(audioUrl, { responseType: 'arraybuffer' }); const base64str = Buffer.from(audioResponse.data).toString('base64');  const payload = {   model: 'gpt-4o-audio-preview',   modalities: ['text'],   messages: [     {       role: 'user',       content: [         { type: 'text', text: 'Please transcribe this audio recording.' },         { type: 'input_audio', input_audio: { data: base64str, format: 'mp3' } }       ]     }   ],   store: true, };  const apiResponse = await axios.post('https://api.openai.com/v1/chat/completions', payload, {   headers: { 'Content-Type': 'application/json' }, });  return {   Result: apiResponse.data.choices[0].message.content,   ID: apiResponse.data.id,   Created: new Date(apiResponse.data.created * 1000).toLocaleString(),   Model: apiResponse.data.model, }; 


Optional: Filter by Execution Time (for Scheduled Triggers)

To upload only recent files, you can filter data based on when the trigger was executed:

const minutesAgo = new Date(__executionStartTime__ - context?.inputData?.scheduledTime * 60 * 1000); 

This calculates the time X minutes before the trigger ran.