Does saving files incur a cost on Vercel?

So I need to chunk out large audio files(20-50mb) that are uploaded to my website, and break those out into 10 min chunks. I wrote the following snippet to do that
async function fetchAndChunkAudio(url: string): Promise<string[]> {
const response = await fetch(url);
const arrayBuffer = await response.arrayBuffer();
const buffer = Buffer.from(arrayBuffer);
const tempFileName = `temp_audio_${Date.now()}`;
const tempFilePath = `./src/app/api/chunkedaudio/temp/${tempFileName}.mp3`;
await fsPromises.writeFile(tempFilePath, buffer);

return new Promise((resolve, reject) => {
let chunks: string[] = [];
ffmpeg(tempFilePath)
.outputOptions([
`-f segment`,
`-segment_time 600`, // Segment time in seconds, adjust if needed
`-segment_format mp3`,
`-segment_list_size 0`, // No maximum list size
`-segment_wrap 0`, // No wrapping
])
.output(`./src/app/api/chunkedaudio/temp/${tempFileName}_%03d.mp3`) // Output path for chunks
.on("end", () => {
chunks = glob.sync(
`./src/app/api/chunkedaudio/temp/${tempFileName}_*.mp3`,
); // Collect chunk files

(async () => {
await fsPromises.unlink(tempFilePath);
})().catch((err) => {
console.error(
`Error deleting initial temp file ${tempFilePath}:`,
err,
);
reject(err);
});

resolve(chunks);
})
.on("error", (err: Error) => {
console.error("Error during processing", err);
reject(err);
})
.run();
});
}
async function fetchAndChunkAudio(url: string): Promise<string[]> {
const response = await fetch(url);
const arrayBuffer = await response.arrayBuffer();
const buffer = Buffer.from(arrayBuffer);
const tempFileName = `temp_audio_${Date.now()}`;
const tempFilePath = `./src/app/api/chunkedaudio/temp/${tempFileName}.mp3`;
await fsPromises.writeFile(tempFilePath, buffer);

return new Promise((resolve, reject) => {
let chunks: string[] = [];
ffmpeg(tempFilePath)
.outputOptions([
`-f segment`,
`-segment_time 600`, // Segment time in seconds, adjust if needed
`-segment_format mp3`,
`-segment_list_size 0`, // No maximum list size
`-segment_wrap 0`, // No wrapping
])
.output(`./src/app/api/chunkedaudio/temp/${tempFileName}_%03d.mp3`) // Output path for chunks
.on("end", () => {
chunks = glob.sync(
`./src/app/api/chunkedaudio/temp/${tempFileName}_*.mp3`,
); // Collect chunk files

(async () => {
await fsPromises.unlink(tempFilePath);
})().catch((err) => {
console.error(
`Error deleting initial temp file ${tempFilePath}:`,
err,
);
reject(err);
});

resolve(chunks);
})
.on("error", (err: Error) => {
console.error("Error during processing", err);
reject(err);
})
.run();
});
}
This runs fine locally, my only concern is I'm not sure what costs look like for saving files to the temp folder in vercel, and couldn't really find info on the pricing page? Am I randomly gonna get hit with a $1000 bill? Files get immediately deleted at the end of the API call if that matters.
5 Replies
nc0
nc06mo ago
I don't think so as long as they stay within the allowed storage cap. However you will use way more bandwidth than usual and therefore will likely get hit with a $1k bill
Ben
BenOP6mo ago
Ya I'm trying to think how we could reduce bandwidth because it does feel like I'm doing a lot of repeated uploading of the same file: 1) Upload the file to uploadthing so I have somewhere to store it 2) Download the file from uploadthing on our Server 3) Chunk the audio using the above code 4) Send the chunks from the server to whisper to get a transcription Not sure if their is a step to be skipped here? But if I understand correctly, for a 20mb file, I'm actually incurring 60mb of bandwith cost? That said I'm already on the pro tier, so it looks like I have a fair amount of bandwith to use? I'm actually confused as to which category this fits into on their current pricing table.
nc0
nc06mo ago
Do you really need uploadthing here? Cause you are doing 2 bandwidth stuff there Directly download it to your server You don't need something else Also maybe own your backend instead of relying on Vercel stuff It sounds way more efficient and cheaper to learn and do so
Ben
BenOP6mo ago
Yes, the component looks something like this, I need it to be uploaded to uploadthing in order for users to be able to download their audio at a later date.
No description
nc0
nc06mo ago
Why not download it from your own server instead? It removes a dependency (avoid vector attack), it's cheaper in badnwidth and storage, you get more control over the features and security you can over, and you own your reliability instead of having the SLA of external stuff as a dependency
Want results from more Discord servers?
Add your server