Skip to content

The problem with access to the file after it is moved  #1009

Description

@zheoreh

For example I uploaded Labs.all.screens.pdf into my backet 'aifiles'.
I get a link to the file as follows (coffescript)


fileOptions =
  action: 'read',
  expires: '01-01-2100'

destination = path + '/' + fileName

    file = bucket.file destination
    uploadStream = file.createWriteStream();
....

uploadStream.on 'finish', ->
      file.getSignedUrl fileOptions, (err, url) =>
        return done err if err
        done null, url

And file link works for me.
https://storage.googleapis.com/aifiles/uploads%2Fapps%2Facme_theme_park%2F9a52117f-0254-4967-b97f-569fbfb0542b%2FLabs.all.screens.pdf?GoogleAccessId=850766160460-cjosh1hn0tfqn1d2efenvcgm0hcoi5gf@developer.gserviceaccount.com&Expires=4102444800&Signature=bqPGuzFRzRYVlWtBvbRbGXEnZZzkFs5ap%2B2OBOklWW9LM0WttBL%2BGTqQAJhlkOpihpPz5vg1DYdPsaLzdcJ6U8OFwsOHZiwJfyxNTwwi32RAWhU%2FfIC3MnOjMpT%2BB1irudspHfwPaDK6XvtBAhBnqn%2FmFBR%2FUsCaLLpxweFsHf8bZuFnAuOwU87VFgMSbB4GveVFxU2n6LRY9JTPhMhkASCnqRk26H7BmfKmEnS9LIHeaLynQyZoqrwuCN%2F74%2FFCSeAaL4886E1sw055EXtiWUmGtx9E%2FlqYj34d0XKau7%2B4JrVpU9sxHqqtd9IskDpSNu8ptk%2FaHoueqTKkD6kmsA%3D%3D

But after moving the file as follows (coffescript):

move: (filePath, newFilePath, done) ->
    file = bucket.file filePath

    file.move newFilePath, (err, destinationFile, apiResponse) ->
      if err
        done err
      else
        destinationFile.getSignedUrl fileOptions, (err, url) =>
          return done err if err
          done null, url, apiResponse

new file link doesn't work for me:

https://storage.googleapis.com/aifiles/uploads%2Fapps%2Facme_theme_park%2F9a52117f-0254-4967-b97f-569fbfb0542b%2FLabs.pdf?GoogleAccessId=850766160460-cjosh1hn0tfqn1d2efenvcgm0hcoi5gf@developer.gserviceaccount.com&Expires=4102444800&Signature=rZ5PZwpY8f9jhsMIBr%2BDw49cFe39mc89N%2FCT6iy067ahtT4xnO%2FV8Tn%2F3SFXAP9GaQzX9ijzrUTqxwXlyDRTqz02vxBjwaxYAsLYI8hNrYa0ilWklCYn6f0c6%2BMeGXB%2B9h7BNJHQbXLHeYQrvaLoA0B0ZryIwzCsXiVsw6cmh26x2KAqZ2vcNos%2Fl3G1kUBDGmcUtc4bSdS0sKgO45FIRQmYqowjr5QPi%2FqjftucBlSNll%2BFPv62KQyIV0xEnRYhyoIabTd37BzSkSrjApJZOEBYakA6I6Lesuhjq%2B6AD3Z7rMks%2Bp85vh%2BatMmrTcTmuBXlLGRJz1McciAPisph9w%3D%3D

<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>
GET 4102444800 /aifiles/uploads%2Fapps%2Facme_theme_park%2F9a52117f-0254-4967-b97f-569fbfb0542b%2FLabs.pdf
</StringToSign>
</Error>

Now I tryed upload other file once again and in this time I have a problem with first link

<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>
GET 4102444800 /aifiles/uploads%2Fapps%2Facme_theme_park%2Fbf95eb77-9531-4c5c-914f-db4f32819c3b%2Fcomment.svg
</StringToSign>
</Error>

Full code:

path = require 'path'
conf = require 'nconf'
gcloud = require 'gcloud'

gcs = gcloud.storage
  projectId: conf.get 'GOOGLE_PROJECT_ID'
  keyFilename: path.resolve process.cwd(), conf.get 'GOOGLE_PRIVATE_JSON_KEY'

bucket = gcs.bucket conf.get 'GOOGLE_BUCKET'

fileOptions =
  action: 'read',
  expires: '01-01-2100'


module.exports =
  uploadStream: (fileStream, path, fileName, done) ->
    destination = path + '/' + fileName

    file = bucket.file destination
    uploadStream = file.createWriteStream();

    fileStream.on 'error', (err) ->
      done err

    uploadStream.on 'error', (err) ->
      done err

    uploadStream.on 'finish', ->
      file.getSignedUrl fileOptions, (err, url) =>
        return done err if err
        done null, url


    fileStream.pipe uploadStream

  move: (filePath, newFilePath, done) ->
    file = bucket.file filePath

    file.move newFilePath, (err, destinationFile, apiResponse) ->
      if err
        done err
      else
        destinationFile.getSignedUrl fileOptions, (err, url) =>
          return done err if err
          done null, url, apiResponse

Activity

  1. stephenplusplus commented on Dec 8, 2015

    @stephenplusplus
    Contributor

    Thanks for reporting this! I was able to reproduce this. It doesn't look like our code is doing anything wrong in this situation. I wonder if this is an upstream issue? @jgeewax

  2. stephenplusplus commented on Dec 8, 2015

    @stephenplusplus
    Contributor

    Also, here is the example converted to JS for us non-:coffee: folk :) https://gist.github.com/stephenplusplus/5bf537da70df0c9db36c

  3. jgeewax commented on Dec 8, 2015

    @jgeewax
    Contributor

    I'm having a bit of trouble following, are you saying:

    1. Create a file
    2. Move the file
    3. Get a signed URL
    4. Signed URL is invalid

    ?

  4. stephenplusplus commented on Dec 8, 2015

    @stephenplusplus
    Contributor

    Yep, and the signed url works when it's done before the move (move = copy to new file and delete original).

  5. DeWenS commented on Dec 9, 2015

    @DeWenS

    Found solution
    var fileOptions = { action: 'read', expires: '01-01-2100' };

    should be inside uploadStream and move functions, because getSignedUrl added "recource" prop to this object, which causes error

  6. jgeewax commented on Dec 9, 2015

    @jgeewax
    Contributor

    That sounds about right. If we're modifying the fileOptions object, those changes would be sticky and carry over to the next call, right?

  7. jgeewax commented on Dec 9, 2015

    @jgeewax
    Contributor

    Can we maybe operate on a copy of the configuration ...?

  8. stephenplusplus commented on Dec 9, 2015

    @stephenplusplus
    Contributor

    Good catch, sorry I missed that.

  9. jgeewax commented on Dec 9, 2015

    @jgeewax
    Contributor

    I'm actually going to re-open this for @stephenplusplus to look at today :)

  10. reopened this on Dec 9, 2015
  11. added
    type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.
    on Dec 9, 2015
  12. added a commit that references this issue on Jan 28, 2026
  13. added a commit that references this issue on Feb 5, 2026
  14. added a commit that references this issue on Feb 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

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