Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
zheoreh opened this issue Dec 8, 2015 · 9 comments
Closed

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

zheoreh opened this issue Dec 8, 2015 · 9 comments
Assignees
Labels
api: storage Issues related to the Cloud Storage API. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@zheoreh
Copy link

zheoreh commented Dec 8, 2015

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

@stephenplusplus stephenplusplus added the api: storage Issues related to the Cloud Storage API. label Dec 8, 2015
@stephenplusplus
Copy link
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

@stephenplusplus
Copy link
Contributor

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

@jgeewax
Copy link
Contributor

jgeewax commented Dec 8, 2015

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

?

@stephenplusplus
Copy link
Contributor

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

@DeWenS
Copy link

DeWenS commented Dec 9, 2015

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

@jgeewax
Copy link
Contributor

jgeewax commented Dec 9, 2015

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

@jgeewax
Copy link
Contributor

jgeewax commented Dec 9, 2015

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

@stephenplusplus
Copy link
Contributor

Good catch, sorry I missed that.

@zheoreh zheoreh closed this as completed Dec 9, 2015
@jgeewax
Copy link
Contributor

jgeewax commented Dec 9, 2015

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

@jgeewax jgeewax reopened this Dec 9, 2015
@stephenplusplus stephenplusplus added the type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. label Dec 9, 2015
sofisl pushed a commit that referenced this issue Nov 11, 2022
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [jsdoc](https://github.com/jsdoc/jsdoc) | [`^3.6.4` -> `^4.0.0`](https://renovatebot.com/diffs/npm/jsdoc/3.6.11/4.0.0) | [![age](https://badges.renovateapi.com/packages/npm/jsdoc/4.0.0/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/npm/jsdoc/4.0.0/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/npm/jsdoc/4.0.0/compatibility-slim/3.6.11)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/npm/jsdoc/4.0.0/confidence-slim/3.6.11)](https://docs.renovatebot.com/merge-confidence/) |

---

### Release Notes

<details>
<summary>jsdoc/jsdoc</summary>

### [`v4.0.0`](https://github.com/jsdoc/jsdoc/blob/HEAD/CHANGES.md#&#8203;400-November-2022)

[Compare Source](https://github.com/jsdoc/jsdoc/compare/3.6.11...084218523a7d69fec14a852ce680f374f526af28)

-   JSDoc releases now use [semantic versioning](https://semver.org/). If JSDoc makes
    backwards-incompatible changes in the future, the major version will be incremented.
-   JSDoc no longer uses the [`taffydb`](https://taffydb.com/) package. If your JSDoc template or
    plugin uses the `taffydb` package, see the
    [instructions for replacing `taffydb` with `@jsdoc/salty`](https://github.com/jsdoc/jsdoc/tree/main/packages/jsdoc-salty#use-salty-in-a-jsdoc-template).
-   JSDoc now supports Node.js 12.0.0 and later.

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "after 9am and before 3pm" (UTC), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://app.renovatebot.com/dashboard#github/googleapis/nodejs-dialogflow).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNC4xNy4xIiwidXBkYXRlZEluVmVyIjoiMzQuMTcuMSJ9-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: storage Issues related to the Cloud Storage API. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

4 participants