fsspec / gcsfs

Pythonic file-system interface for Google Cloud Storage
http://gcsfs.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
345 stars 146 forks source link

Missing 'name' attribute in 'GCSFile' object when accessing PDF files #617

Open bhavan-kaya opened 8 months ago

bhavan-kaya commented 8 months ago

Description: In the context of using gcsfs with llama-index for reading files from a GCP bucket, an error occurs for PDF files indicating that the 'GCSFile' object has no attribute 'name'. This issue does not occur when accessing DOCX files. It suggests that there may be an inconsistency or a bug in how gcsfs handles file metadata, specifically for PDF files.

import google.auth
from llama_index.core import SimpleDirectoryReader
from gcsfs import GCSFileSystem
from fs_gcsfs import GCSFS

def __load_gcp_bucket(bucket_path: str):
    credentials, project_id = google.auth.default(
        scopes=["https://www.googleapis.com/auth/devstorage.read_only"]
    )

    gcp_fs = GCSFileSystem(project=project_id, token=credentials)

    reader = SimpleDirectoryReader(
        input_dir=bucket_path,
        fs=gcp_fs,
    )

    documents = reader.load_data()
    return documents

documents = __load_gcp_bucket("<bucket-path>/")
print(documents)

Version:

Steps to Reproduce:

  1. Use GCSFileSystem from gcsfs to access files in a GCP bucket.
  2. Attempt to read metadata from both .pdf and .docx files.
  3. Compare the behavior and output to identify the absence of the name attribute in the case of PDF files.

Relevant Logs/Tracebacks:

Failed to load file <GCS bucket path>/file.pdf with error: 'GCSFile' object has no attribute 'name'. Skipping...
martindurant commented 8 months ago

Please show the full traceback, so we can see what llama_index is trying to do. You may also want to cross-post on their tracker. No GCSFile has a .name, but they do have a .path .