thaiphan / magento2-s3

Use Amazon S3 as the file storage solution for your Magento 2 application
MIT License
142 stars 95 forks source link

Unable to unserialize value, string is corrupted. #55

Closed mukdam closed 6 years ago

mukdam commented 6 years ago

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;
}`
NSanthoshpriya commented 6 years ago

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?

ata333 commented 6 years ago

@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; }

}

thaiphan commented 6 years ago

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

thaiphan commented 6 years ago

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