ramluro
ramluro

Reputation: 87

Error: Invalid HTTP method/URL pair when using getDownloadURL on a file produced by the Transcoder API

I am using the Transcoder API to format videos into a 1:1 aspect ratio. The source video file is stored in a Firebase Storage bucket. When the transcoded file is generated, it does not have an access token, so to view the file, I can manually create the access token using the console. This way I am able to get a URL that I use to access the transcoded file.

I want generate a download URL in my cloud function for the the ChromeCast.mp4 file in picture below: enter image description here

When I run the following code, I get "Error: Invalid HTTP method/URL pair." in my log with the following code:

            // Create a download URL for transcoded file

            const { getStorage, getDownloadURL } = require('firebase-admin/storage');

            var newBucket = `*MY-BUCKET-NAME*.appspot.com/transcoder/`
            var newName = `ChromeCast.mp4`;

            console.log(`newBucket: ${newBucket}`);
            console.log(`newName: ${newName}`);

            const fileRef = getStorage().bucket(`${newBucket}`).file(`${newName}`);
            const downloadURL= await getDownloadURL(fileRef);

            console.log(downloadURL);

The line "const downloadURL= await getDownloadURL(fileRef)" is generating the error. I have tried the following variations of the bucket name:

var newBucket = `*MY-BUCKET-NAME*.appspot.com/transcoder%2F`

var newBucket = `*MY-BUCKET-NAME*.appspot.com/transcoder`

But I still get the same error.

I have also tried removing the following code variation, but get 'Error: Not Found'

        var newBucket = `*MY-BUCKET-NAME*.appspot.com`
        var newName = `/transcoder/ChromeCast.mp4`;

        const fileRef = getStorage().bucket(`${newBucket}`).file(`${newName}`);

        const downloadURL= await getDownloadURL(fileRef);

I am using a hardcoded bucket for testing purposes. I want to generate a download URL so I can update a document with the new URL, replacing the URL to original video file

Upvotes: 0

Views: 70

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317750

The string "transcoder" is not part of your bucket name. It's part of the path to the object you're trying to work with. Your variables should look like this:

var newBucket = `*MY-BUCKET-NAME*.appspot.com`
var newName = `transcoder/ChromeCast.mp4`;

Upvotes: 1

Related Questions