Skip to content

firebase admin Fail to Upload files with http 404 error #280

@storyinvisible

Description

@storyinvisible

I am trying to upload an image file to the Firebase storage, However, it keeps on raising an error.

from firebase_admin import credentials
import firebase_admin
from firebase_admin import storage
cred= credentials.Certificate('./digitalworld.json')
firebase_admin.initialize_app(cred, {
'storageBucket': 'gs://digitalworldf08g2.appspot.com/'
})
bucket=storage.bucket('digitalworldf08g2')
store_name='western_stall'

imagesPath= "./"+"ricc_with_noodle.jpg"
blob=bucket.blob('/{}/'.format(store_name))
blob.upload_from_filename(imagesPath)

Here is the error

Traceback (most recent call last):
  File "C:\Users\Zhibo\AppData\Local\Programs\Python\Python36\lib\site-packages\google\cloud\storage\blob.py", line 1085, in upload_from_file
    client, file_obj, content_type, size, num_retries, predefined_acl
  File "C:\Users\Zhibo\AppData\Local\Programs\Python\Python36\lib\site-packages\google\cloud\storage\blob.py", line 991, in _do_upload
    client, stream, content_type, size, num_retries, predefined_acl
  File "C:\Users\Zhibo\AppData\Local\Programs\Python\Python36\lib\site-packages\google\cloud\storage\blob.py", line 785, in _do_multipart_upload
    response = upload.transmit(transport, data, object_metadata, content_type)
  File "C:\Users\Zhibo\AppData\Local\Programs\Python\Python36\lib\site-packages\google\resumable_media\requests\upload.py", line 98, in transmit
    self._process_response(result)
  File "C:\Users\Zhibo\AppData\Local\Programs\Python\Python36\lib\site-packages\google\resumable_media\_upload.py", line 110, in _process_response
    response, (http_client.OK,), self._get_status_code)
  File "C:\Users\Zhibo\AppData\Local\Programs\Python\Python36\lib\site-packages\google\resumable_media\_helpers.py", line 93, in require_status_code
    status_code, u'Expected one of', *status_codes)
google.resumable_media.common.InvalidResponse: ('Request failed with status code', 404, 'Expected one of', <HTTPStatus.OK: 200>)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\SUTD\digitalworld\Digital1D\google_storage.py", line 39, in <module>
    upload_fire()
  File "D:\SUTD\digitalworld\Digital1D\google_storage.py", line 25, in upload_fire
    blob.upload_from_filename(imagesPath)
  File "C:\Users\Zhibo\AppData\Local\Programs\Python\Python36\lib\site-packages\google\cloud\storage\blob.py", line 1140, in upload_from_filename
    predefined_acl=predefined_acl,
  File "C:\Users\Zhibo\AppData\Local\Programs\Python\Python36\lib\site-packages\google\cloud\storage\blob.py", line 1089, in upload_from_file
    _raise_from_invalid_response(exc)
  File "C:\Users\Zhibo\AppData\Local\Programs\Python\Python36\lib\site-packages\google\cloud\storage\blob.py", line 1960, in _raise_from_invalid_response
    raise exceptions.from_http_status(response.status_code, message, response=response)
google.api_core.exceptions.NotFound: 404 POST https://www.googleapis.com/upload/storage/v1/b/digitalworldf08g2/o?uploadType=multipart: ('Request failed with status code', 404, 'Expected one of', <HTTPStatus.OK: 200>)

I have tried with
blob.exist()
and the output is false

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions