Skip to content

double leading slash when uploading a file to a bucket #1972

Closed

Description

@kilianc

Environment details

  • OS: GKE
  • Node.js version: 7
  • npm version: 4.0.5
  • google-cloud-node version: "@google-cloud/storage": "^0.5.0"

Steps to reproduce

const bucket = Storage().bucket('gs://my-name')
const file = bucket.file('/foo/bar/lol.txt')
const readStream = fs.createReadStream('./lol.txt')
const writeStream = file.createWriteStream({ metadata: { contentType: 'text/plain' } })
readStream.pipe(writeStream)

Given the above code it uploads a file at gs://my-name//foo/bar/lol.txt

Activity

  1. stephenplusplus commented on Feb 7, 2017

    @stephenplusplus
    Contributor

    The bucket name should simply be my-name, not its URL:

    - const bucket = Storage().bucket('gs://my-name')
    + const bucket = Storage().bucket('my-name')

    And same for the file method:

    - const file = bucket.file('/foo/bar/lol.txt')
    + const file = bucket.file('foo/bar/lol.txt')

    With these changes, the file uploaded should land at: gs://my-name/foo/bar/lol.txt.

    I don't think it'd be a big change if our library auto-removed any leading slashes from the input to bucket.file(), but given the explanation above of the correct way to use these methods, do you think it's necessary?

  2. kilianc commented on Feb 7, 2017

    @kilianc
    Author

    @stephenplusplus I was using only my-name indeed, I messed up while trying to extract the use case.

    given the explanation above of the correct way to use these methods, do you think it's necessary?

    Since I am not feeding the library anywhere a double leading slash it is very strange that this is the outcome. I mean my-name + /foo -> my-name/foo. I understand the other way around where in case of a missing leading slash it's assumed the user means root.

    In my opinion this is straight up a bug, I can't think of anybody that needs to upload a file to something//file.txt IMHO.

    🍻

  3. stephenplusplus commented on Feb 7, 2017

    @stephenplusplus
    Contributor

    You're right, that is weird. I'll mark as help wanted, so if anybody wants to strip leading / from within the File constructor, please help!

  4. stephenplusplus commented on Feb 7, 2017

    @stephenplusplus
    Contributor

    Oh, and 🍻

  5. kilianc commented on Feb 7, 2017

    @kilianc
    Author

    I am looking at the code, I'll def try to help

  6. added
    priority: p2Moderately-important priority. Fix may not be included in next release.
    type: questionRequest for information or clarification. Not an issue.
    on Feb 27, 2017
  7. removed
    priority: p2Moderately-important priority. Fix may not be included in next release.
    on May 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

api: storageIssues related to the Cloud Storage API.type: questionRequest for information or clarification. Not an issue.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions