thaiphan/magento2-s3

Unable to unserialize value, string is corrupted.

mukdam opened this issue · 4 comments

I am saving store config value without a header and upload an image in catalog product showing error Unable to unserialize value, string is corrupted.

In below file for $this->serializer object we call function getSerializer.So in Magento 2.1, it's working Because of use Serializer.php class in Magento via SerializerInterface.
So you need to call SerializerInterface like below Magento change to JSON

`public function __construct(
Magento\Framework\Serialize\SerializerInterface $serializer,
\Thai\S3\Helper\Data $helper,
\Magento\MediaStorage\Helper\File\Media $mediaHelper,
\Magento\MediaStorage\Helper\File\Storage\Database $storageHelper,
\Psr\Log\LoggerInterface $logger
) {
parent::__construct();

    $this->helper = $helper;
    $this->mediaHelper = $mediaHelper;
    $this->storageHelper = $storageHelper;
    $this->logger = $logger;
    $this->serializer = $serializer;`

Thai\S3\Model\MediaStorage\File\Storage\S3.php
`protected function getSerializer()
{
// Magento Version 2.1.*
$serializer = \Zend\Serializer\Serializer::factory(\Zend\Serializer\Adapter\PhpSerialize::class);

    // Magento Version 2.2.*
    if (class_exists(\Magento\Framework\Serialize\Serializer\Serialize::class)) {
        $serializer = \Magento\Framework\App\ObjectManager::getInstance()->get(
            \Magento\Framework\Serialize\Serializer\Serialize::class
        );
    }
    return $serializer;
}`

I have the Same problem. But I actually get the below error.
image
When I debug it I find the Unable to unserialize value, the string is corrupted, Error

Did you find any solution?

@NSanthoshpriya Hey I fixed it by overriding the serializer method , this code also fixes @mukdam issue

class S3Modifed extends \Thai\S3\Model\MediaStorage\File\Storage\S3
{
protected $mySerializer;
public function __construct(
\Thai\S3\Helper\Data $helper,
\Magento\MediaStorage\Helper\File\Media $mediaHelper,
\Magento\MediaStorage\Helper\File\Storage\Database $storageHelper,
\Psr\Log\LoggerInterface $logger) {
parent::__construct($helper,$mediaHelper,$storageHelper,$logger);
}
protected function getSerializer()
{
// you always have to use Object manager in static magic methods like serialize*
$serializer = \Magento\Framework\App\ObjectManager::getInstance()->get(\Magento\Framework\Serialize\Serializer\Json::class);
return $serializer;
}

}

Hi @mukdam, @NSanthoshpriya and @ata333

Many apologies for taking so long to getting around to fixing this!

I have switched over to using the JSON deserialiser as you suggested! I've done some testing and it looks like the problem that you are describing is no longer happening.

This change has been deployed as v1.3.2. Can you update and advise if this latest update resolves your problems?

Regards,

Thai

I'm closing this issue because it's a duplicate of #50. Can you guys post to that issue instead if problems persist?