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

Invalid field selection name. (StorageObject exists() funciton) #6636

Closed
mahmoudabdelhalim opened this issue Sep 17, 2023 · 4 comments
Closed
Assignees
Labels
api: storage Issues related to the Cloud Storage API.

Comments

@mahmoudabdelhalim
Copy link

First I use the package to upload the files bucket.

I got this error.

{
    "error": {
        "code": 400,
        "message": "Invalid field selection name",
        "errors": [
            {
                "message": "Invalid field selection name",
                "domain": "global",
                "reason": "invalidParameter",
                "locationType": "parameter",
                "location": "fields"
            }
        ]
    }
}

The error happens when I try to check if the file exists on the bucket.

the sample code:

$bucket = $storage->bucket($bucketName);
$object = $bucket->object($file_name);
$exists = $object->exists();

The " $object->exists(); " is the reason.

#0 /var/www/wetrn.ai/vendor/google/cloud-core/src/RequestWrapper.php(214): Google\\Cloud\\Core\\RequestWrapper->convertToGoogleException()
#1 /var/www/wetrn.ai/vendor/google/cloud-core/src/RestTrait.php(102): Google\\Cloud\\Core\\RequestWrapper->send()
#2 /var/www/wetrn.ai/vendor/google/cloud-storage/src/Connection/Rest.php(730): Google\\Cloud\\Storage\\Connection\\Rest->traitSend()
#3 /var/www/wetrn.ai/vendor/google/cloud-storage/src/Connection/Rest.php(250): Google\\Cloud\\Storage\\Connection\\Rest->send()
#4 /var/www/wetrn.ai/vendor/google/cloud-storage/src/StorageObject.php(147): Google\\Cloud\\Storage\\Connection\\Rest->getObject()
#5 /var/www/wetrn.ai/app/Jobs/GoogleCloudStorageUploaderJob.php(67): Google\\Cloud\\Storage\\StorageObject->exists()

@bshaffer @yash30201

Thanks!

@bshaffer
Copy link
Contributor

bshaffer commented Sep 17, 2023 via email

@mahmoudabdelhalim
Copy link
Author

@bshaffer

Hello Bshaffer,

I use it to check if the file exists before uploading.


$storage = new StorageClient([
    'keyFilePath' => 'key file path',
]);

$bucket = $storage->bucket('my-bucket');
$object = $bucket->object('file_name');
$exists = $object->exists(); // ERROR HAPPEN HERE!

// Then upload the code here...
$fileContents = file_get_contents('filelinkhere'');
$storageObject = $bucket->upload($fileContents, [
    'predefinedAcl' => 'publicRead',
    'name' => 'file_name'
]);

@bshaffer
Copy link
Contributor

I was unable to replicate this error with my credentials. I copied your code directly, but substituted my own project, bucket, and credentials, and the call to exists worked just fine.

Have you updated to the latest version of the storage client library and it's dependencies?

@saranshdhingra
Copy link
Contributor

Hi @mahmoudabdelhalim
We haven't received your reply in a month.

I'll be closing this issue for now but please feel free to reopen this if you are able to reproduce this issue.
Thanks.

@saranshdhingra saranshdhingra added the api: storage Issues related to the Cloud Storage API. label Oct 17, 2023
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.
Projects
None yet
Development

No branches or pull requests

4 participants