question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`Blob.upload_from_filename` fails silently if the blob name starts with '/'

See original GitHub issue

Using google-cloud-storage==1.2.0, attempting to upload files using Blob.upload_from_filename fails silently (i.e. no error is raised but the blob is not uploaded) if the blob name starts with a forward slash /. A basic example is given below.

import google.cloud.storage

client = google.cloud.storage.Client()
bucket = client.get_bucket('some-bucket')
blob = bucket("/some-blob")
blob.upload_from_filename("some-file")

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
tillahoffmanncommented, Aug 15, 2017

I can no longer reproduce this issue using 1.3.0.

0reactions
tseavercommented, Jun 7, 2021

I still cannot reproduce this issue:

$ python3.9 -m venv /tmp/repro-gcp-3675
$ /tmp/repro-gcp-3675/bin/pip install google-cloud-storage
...
Successfully installed cachetools-4.2.2 certifi-2021.5.30 cffi-1.14.5 chardet-4.0.0 google-api-core-1.29.0 google-auth-1.30.1 google-cloud-core-1.6.0 google-cloud-storage-1.38.0 google-crc32c-1.1.2 google-resumable-media-1.3.0 googleapis-common-protos-1.53.0 idna-2.10 packaging-20.9 protobuf-3.17.2 pyasn1-0.4.8 pyasn1-modules-0.2.8 pycparser-2.20 pyparsing-2.4.7 pytz-2021.1 requests-2.25.1 rsa-4.7.2 six-1.16.0 urllib3-1.26.5
$ cat > /tmp/my_file.csv
"Date","Action","Count"
"2021-06-07","Testing", 1
$ cat /tmp/repro-gcp-3675/repro_gcp_3675.py 
from google.cloud.storage import Client

BUCKET_NAME = "repro-gcp-3675"
BLOBNAME = "/my_file.csv"
FILENAME = f"/tmp{BLOBNAME}"

def main():
    client = Client()
    bucket = client.get_bucket(BUCKET_NAME)
    blob = bucket.blob(BLOBNAME)
    blob.upload_from_filename(FILENAME)

    assert blob.exists()

    assert BLOBNAME in [blob.name for blob in bucket.list_blobs()]


if __name__ == "__main__":
    main()
$ /tmp/repro-gcp-3675/bin/python /tmp/repro-gcp-3675/repro_gcp_3675.py
$

Note that the google-cloud-storage library is no longer maintained in this repository. If you can provide a reproducible case for this issue, please open a new issue in the new repository.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Upload file to Google Cloud with Python 3 problem
There is a problem in the second last line blob.upload_from_filename(filename) and I want to know how to fix this problem. Here is the...
Read more >
Class Blob (2.7.0) | Python client library - Google Cloud
Deletes a blob from Cloud Storage. If user_project is set on the bucket, bills the API request to that project. Parameters. Name, Description....
Read more >
Quickstart: Azure Blob Storage library v12 - C++
In this quickstart, you learn how to use the Azure Blob Storage client library version 12 for C++ to create a container and...
Read more >
Blobs / Objects — google-cloud 0.20.0 documentation
GoogleCloudError if the upload response returns an error status. upload_from_filename (filename, content_type=None, encryption_key=None, client=None)[source] ...
Read more >
Python - Google Cloud
No information is available for this page.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found