I have searched widely for this problem but to no avail. Here’s the code that’s giving me the issue.
if ($request->hasFile("images")) {
foreach ($request->file("images") as $i => $image) {
$path = $image->storePubliclyAs($product->id, "image_$i.{$image->extension()}");
}
}
The line with $image->storePubliclyAs()
is raising the error:
InvalidArgumentException: Found 1 error while validating the input provided for the GetObject operation:
[Key] expected string length to be >= 1, but found string length of 0 in file /var/www/html/vendor/aws/aws-sdk-php/src/Api/Validator.php on line 65
I should note that I’ve already indicated in the .env
file that the filesystem disk should be pointed to S3. The bucket’s objects are also entirely public. This is quite confusing as $image->storeAs()
works perfectly fine.
2
Answers
Found a workaround. Instead of using the
storePubliclyAs()
method, just usestoreAs()
andStorage::setVisibility()
respectively:Kind of weird but it's been the only way I could get it to work.
Can you try this code below. I just changed how you are using $i in giving the image a name.