nodejs-storage icon indicating copy to clipboard operation
nodejs-storage copied to clipboard

Invalid Expires property when generating a signed URL to write and read to in the @google-cloud/storage package

Open gavinwilliams opened this issue 9 years ago • 2 comments

Is anyone having issues with generating a valid signed url for Cloud Storage? I'm getting the following error when I try to PUT to the final URL.

<?xml version='1.0' encoding='UTF-8'?>
<Error>
    <Code>InvalidArgument</Code>
    <Message>Invalid argument.</Message>
    <Details>Expires parameter is not a valid long value: NaN</Details>
</Error>

Looking at the URL, it contains Expires=NaN. Even without an expires property in the getSignedUrl config it still says NaN.

Long shot, but manually setting the expires property gives me the following error.

<?xml version='1.0' encoding='UTF-8'?>
<Error>
    <Code>SignatureDoesNotMatch</Code>
    <Message>The request signature we calculated does not match the signature you provided. Check your Google secret key and signing method.</Message>
    <StringToSign>PUT

video/mp4
1508619214
/xxx-xxx/D48641F8-D1BC-424E-8115-FB1BD3599B89_f9f2537d-cedf-443e-b1da-0c32031d16b0.mp4</StringToSign>
</Error>

Environment details

  • OS: macOS 10.3.1 Beta
  • Node.js version: v8.4.0
  • ~~npm~~ yarn version: 0.18.1
  • google-cloud-node version: 1.4.0

Steps to reproduce

  1. require @google-cloud/storage
  2. Create a new storage object
        const storage = Storage({
            projectId: 'your-project',
            keyFilename: appConfig.gcloud.credentials(),
        });
  1. Request a signed URL
        const expires = moment();
        expires.add(7, 'days');
        result = await storage
                        .bucket('your-bucket')
                        .file('myfile.mp4')
                        .getSignedUrl({
                            action: 'write',
                            expires: expires.format('DD-MM-YYYY'),
                            contentType: 'video/mp4',
                        });
  1. PUT to the signed URL with Postman with header values and a video as a binary in the body.
[{"key":"Content-Type","value":"video/mp4","description":""}]

gavinwilliams avatar Oct 22 '17 00:10 gavinwilliams

Fixed it by changing the data format to YYYY-MM-DD.

gavinwilliams avatar Oct 22 '17 01:10 gavinwilliams

Spent 5 hours on this.

amsakanna avatar Apr 01 '18 16:04 amsakanna