jackFlick's avatar

Temporary URL if the avatar column is null

I'm uploading a private file using s3 driver and showing the file with expiration. It works fine if there's an uploaded file but if the avatar is null it gives an error

here's what's inside my Resource

'avatar' => Storage::temporaryUrl(
                $this->avatar,
                now()->addMinutes(5)
            ),

and the error i get

"message": "Found 1 error while validating the input provided for the GetObject operation:\n[Key] expected string length to be >= 1, but found string length of 0",
    "exception": "InvalidArgumentException",
    "file": "D:\xampp\htdocs\DCTS\paradigm\vendor\aws\aws-sdk-php\src\Api\Validator.php",
    "line": 65,

Is there a way i can still pull my resource and show the avatar NULL if no file is uploaded?

0 likes
3 replies
shez1983's avatar

so normally you would CHECK That first in ur e.g check this->avatar is null or not and then use the tempUrl() func.. if null u usually have some kind of placeholder image that wud show up so no need to make that private just use normal public folder link / s3 etc

Snapey's avatar
Snapey
Best Answer
Level 122
'avatar' => is_null($this->avatar) ? null : Storage::temporaryUrl(
                $this->avatar,
                now()->addMinutes(5)
            ),

2 likes

Please or to participate in this conversation.