GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — storage/file#getSignedUrl example for uploading to signed URL fails · Issue #1312 · googleapis/google-cloud-node

storage/file#getSignedUrl example for uploading to signed URL fails #1312

New issue
Copy link
New issue
Copy link
Closed
Closed
storage/file#getSignedUrl example for uploading to signed URL fails#1312
Copy link
Assignees
yoshi-automation
Labels
api: storageIssues related to the Cloud Storage API.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Description

@aknuds1
aknuds1
opened on May 13, 2016
Issue body actions

I cannot upload to signed URLs generated by storage/file#getSignedUrl. I've even tried implementing the official example from the documentation and it fails:

let bucket = gcs.bucket('aBucket')
let cloudFile = bucket.file('aFile')
cloudFile.getSignedUrl({
  action: 'write',
  expires: `03-17-2025`,
}, (error, signedUrl) => {
  if (error == null) {
    // The file is now available to be written to.
    let request = require('request')
    var writeStream = request.post(signedUrl);
    writeStream.end('New data');
    writeStream.on('complete', function(resp) {
      if (resp.statusCode !== 200) {
        console.log('Writing to file failed:', resp.statusCode)
      } else {
        // Confirm the new content was saved.
        cloudFile.download(function(err, fileContents) {
          if (err != null) {
            console.log(`Download failed:`, err.message)
          } else {
            console.log('Contents:', fileContents.toString());
          }
        });
      }
    });
  }
})

The status code from POSTing to the file is 400, with the message <?xml version='1.0' encoding='UTF-8'?><Error><Code>InvalidPolicyDocument</Code><Message>The content of the form does not meet the conditions specified in the policy document.</Message><Details>Missing policy</Details></Error>%.

Activity

Next
  1. stephenplusplus
    added
    api: storageIssues related to the Cloud Storage API.
    type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.
    docs
    on May 13, 2016
  2. stephenplusplus commented on May 13, 2016

    @stephenplusplus
    stephenplusplus
    on May 13, 2016
    Contributor
    More actions

    Bug caught, PR sent: #1313! When action is write, we generate a signed url expecting a PUT request.

    Note: The HTTP verb POST is not supported in signed URL strings, except as noted above. You can use POST to define signed policy documents, which specify the characteristics of objects that can be uploaded to a bucket. Learn more in the POST Object documentation

    • https://cloud.google.com/storage/docs/access-control/signed-urls
  3. callmehiphop
    closed this as completedin #1313on May 13, 2016
  4. aknuds1 commented on May 13, 2016

    @aknuds1
    aknuds1
    on May 13, 2016
    ContributorAuthor
    More actions

    Thanks @stephenplusplus! PUT doesn't quite work for me either, although it fails in a different way. If I try curl -X put -d "{}" $SIGNED_URL it fails like this:

    <?xml version='1.0' encoding='UTF-8'?><Error><Code>AccessDenied</Code><Message>Access denied.</Message><Details>Anonymous callers do not have storage.objects.create access to bucket arve.muzhack.com.</Details></Error>
    

    If I try to PUT via XMLHttpRequest, it fails differently:

    let request = new XMLHttpRequest()
    request.onreadystatechange = () => {
      if (request.readyState === XMLHttpRequest.DONE) {
        if (request.status === 200) {
          console.log('Uploaded successfully')
        } else {
          console.log(`Upload was not successful: ${request.status}`)
        }
      }
    }
    
    request.open('PUT', signedUrl, true)
    request.send(file)
    

    Resulting in the following response:

    <?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
    
    image/png
    1463260982
    /arve.muzhack.com/u%2Faknudsen%2Ftest%2Fpictures%2FIMG_20160511_132145.jpg</StringToSign></Error>
    

    It would be great if you could help me figure out what goes wrong here.

  5. aknuds1 commented on May 13, 2016

    @aknuds1
    aknuds1
    on May 13, 2016
    ContributorAuthor
    More actions

    I figured out that the reason that XMLHttpRequest fails is that it sends a content-type header, f.ex. image/png, which the call to getSignedUrl fails to match by default. I worked around it by sending a fixed value for content-type, which I also configured getSignedUrl with.

  6. aknuds1 commented on May 13, 2016

    @aknuds1
    aknuds1
    on May 13, 2016
    ContributorAuthor
    More actions

    @stephenplusplus I have another question though. How do I ensure that a file created through uploading via a signed URL is publicly readable? See my Stack Overflow question on this.

  7. stephenplusplus commented on May 13, 2016

    @stephenplusplus
    stephenplusplus
    on May 13, 2016
    Contributor
    More actions

    I believe you can use the extension headers option: https://googlecloudplatform.github.io/gcloud-node/#/docs/v0.33.0/storage%2Ffile?method=getSignedUrl

    See https://cloud.google.com/storage/docs/access-control/signed-urls#about-canonical-extension-headers looks like maybe "x-goog-acl: public"

  8. aknuds1 commented on May 13, 2016

    @aknuds1
    aknuds1
    on May 13, 2016
    ContributorAuthor
    More actions

    @stephenplusplus How do I set extensionHeaders properly? I've tried, but the signature verification fails.

  9. aknuds1 commented on May 13, 2016

    @aknuds1
    aknuds1
    on May 13, 2016
    ContributorAuthor
    More actions

    @stephenplusplus I think there is a bug when supplying extensionHeaders actually. You have to add a newline at the end for it to work, due to the implementation of getSignedUrl:

    var sign = crypto.createSign('RSA-SHA256');
    sign.update([
      options.action,
      (options.contentMd5 || ''),
      (options.contentType || ''),
      expiresInSeconds,
      (options.extensionHeaders || '') + options.resource
    ].join('\n'));
    var signature = sign.sign(credentials.private_key, 'base64');
    

    You'll see that options.extensionHeaders is prepended to options.resource. I don't see any good reason for this, and it means in practice a newline has to be appended to extensionHeaders in order to match the incoming request.

  10. aknuds1 commented on May 14, 2016

    @aknuds1
    aknuds1
    on May 14, 2016
    ContributorAuthor
    More actions

    @stephenplusplus I created an issue on the matter, with accompanying PR.

  11. JustinBeckwith
    assigned
    yoshi-automation
    on Feb 1, 2021
  12. chingor13
    added 2 commits that reference this issue on Aug 22, 2022

    docs(node): support "stable"/"preview" release level (#1312) (#586)

    d61ddf9

    docs(node): support "stable"/"preview" release level (#1312) (#586)

    4063a1c
  13. 143 remaining items

  14. codyoss
    added a commit that references this issue on Mar 5, 2026

    docs(node): support "stable"/"preview" release level (#1312) (#279)

    d3b8a49
  15. GautamSharda
    added 2 commits that reference this issue on Mar 5, 2026

    docs(node): support "stable"/"preview" release level (#1312) (#1203)

    534df1a

    fix: better support for fallback mode (#1312)

    663f183
  16. sofisl
    added a commit that references this issue on Mar 5, 2026

    docs(node): support "stable"/"preview" release level (#1312) (#386)

    451b14c
  17. codyoss
    added 2 commits that reference this issue on Mar 9, 2026

    docs(node): support "stable"/"preview" release level (#1312) (#300)

    746b8bf

    docs(node): support "stable"/"preview" release level (#1312) (#300)

    e58da52
  18. GautamSharda
    added 4 commits that reference this issue on Mar 11, 2026

    docs(node): support "stable"/"preview" release level (#1312) (#1448)

    85d54f6

    docs(node): support "stable"/"preview" release level (#1312) (#283)

    a138f4e

    docs(node): support "stable"/"preview" release level (#1312) (#283)

    5fe0683

    docs(node): support "stable"/"preview" release level (#1312) (#717)

    6ca52f5
  19. thiyaguk09
    added a commit that references this issue on Mar 18, 2026

    docs(node): support "stable"/"preview" release level (googleapis#1312) (

    f2eb98b
  20. GautamSharda
    added 2 commits that reference this issue on Mar 23, 2026

    docs(node): support "stable"/"preview" release level (#1312) (#969)

    bdbd765

    docs(node): support "stable"/"preview" release level (#1312) (#969)

    56a530f
  21. shivanee-p
    added a commit that references this issue on Mar 27, 2026

    docs(node): support "stable"/"preview" release level (#1312) (#969)

    94f0bfa
  22. thiyaguk09
    added a commit that references this issue on May 5, 2026

    docs(node): support "stable"/"preview" release level (googleapis#1312) (

    abac040
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @yoshi-automation
    yoshi-automation

Labels

api: storageIssues related to the Cloud Storage API.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.