Skip to content

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

@zheoreh

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

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