Can't download video file / ai.files.download(). Veo 3 model response

Hi Everyone,

I’m calling the veo 3.0 model but when I try to download the video that I get as a response I must be doing something wrong beacuse the mp4 storage path is empty, it has 0 bytes, and nothing plays on the mp4 player. So it seems it must be a problem of how im downloading the ai.filesdownload() but can’t quite get it solved:

Not sure if anyone has faced a similar issue even if with a different model, and how I could narrow this down. I explain below:

  1. Im calling the veo 3.0 as follows:
// Generate video using Veo 3 and Polling until video ready
          console.log(`Calling Veo 3 API for ${formatName} video...`)
          
          let operation = await ai.models.generateVideos({
            model: "veo-3.0-generate-preview",
            prompt: videoObject.prompt,
            config: {
              aspectRatio: formatData.aspectRatio
            },
          })
          console.log('Video generation operation started:', operation.name) 
  1. Then im polling until the video is ready
          let pollCount = 0
          const maxPolls = 60 // Maximum 10 minutes (60 * 10 seconds)
          
          while (!operation.done && pollCount < maxPolls) {
            console.log(`Waiting for video generation to complete... (poll ${pollCount + 1}/${maxPolls})`)
            await new Promise((resolve) => setTimeout(resolve, 10000)) // Wait 10 seconds
            
            operation = await ai.operations.getVideosOperation({
              operation: operation
            })
            
            pollCount++
          }

          if (!operation.done) {
            throw new Error('Video generation timed out after 10 minutes')
          }

          if (operation.error) {
            throw new Error(`Video generation failed: ${operation.error.message || 'Unknown error'}`)
          }

          console.log('Video generation completed successfully')
  1. Then I’m getting the generated video
// Get the generated video

          const generatedVideo = operation.response?.generatedVideos?.[0]
            if (!generatedVideo?.video) {
            throw new Error('No video data in response')
          }

          console.log('Generated video file:', generatedVideo.video)

Console log above always shows success with the following response, which I assume that means the above is processing correctly:

"Generated video file: {\n  uri: \"https://generativelanguage.googleapis.com/v1beta/files/8bem4xshl3ac:download?alt=media\",\n  videoBytes: undefined,\n  mimeType: undefined\n}\n"
  1. Then Im downloading the generated Video
// Download the video file
          const videoFile = await ai.files.download({
            file: generatedVideo.video
                       
          })

Then I work accross other sections of the component to give a storagePath and a name to the VIdeoFile as follows , to upload to S3/Supabase Storage:

// Preparing  variables to save the Video in S3/Supabase Storage
 
const timestamp = Date.now()
const randomId = Math.random().toString(36).substring(2, 15)
const fileName = `ai-video-${formatName}-${timestamp}-${randomId}.mp4`
const storagePath = `ai-generated-videos/${fileName}`

// Getting user's bucket for storage
          const { data: userBucket, error: bucketError } = await supabaseAdmin
            .from('content_buckets')
            .select('bucket_name')
            .eq('user_id', user.id)
            .limit(1)
            .single()

          if (bucketError || !userBucket) {
            throw new Error('User bucket not found')
          }

// Upload to Supabase storage

          const { data: uploadData, error: uploadError } = await supabaseAdmin.storage
            .from(userBucket.bucket_name)
            .upload(storagePath, videoFile, {
              contentType: 'video/mp4',
              upsert: false
            })

          if (uploadError) {
            throw new Error(`Failed to upload video: ${uploadError.message}`)
          }

          console.log('Video uploaded successfully:', uploadData.path)

//Then I get a sigend URL for display on FrontEnd

// Generate signed URL
          const { data: signedUrlData } = await supabaseAdmin.storage
            .from(userBucket.bucket_name)
            .createSignedUrl(storagePath, 3600) // 1 hour expiry

The problem is that when I load the signed URL I see that the file on that path is empty

Basically I’ve banged my head for the last 4-5 days and tried pretty much everything.

Any help super appreciated! :folded_hands: :folded_hands:

Hello,

Could you please try playing the video to check if it was generated correctly? This will help us determine whether the issue is with the generation process or during the download.