It is occurred on Magento version 1.6.1.0
Product image upload error on Mac OSX.
It’s working fine on Windows but on Mac OSX it shows “Upload HTTP Error” when I clicked “Upload Files”.
After some research I found out that it is caused by HTTP_USER_AGENT validation:
General > Web > Session Validation Settings > Validate HTTP_USER_AGENT
In my site the value is Yes. Everything works fine if I change it into No.
Curiosity is coming.
I trace the code.
I found out that when we click “Upload Files”, it will trigger Mage_Adminhtml_Catalog_Product_GalleryController -> uploadAction
It never reach that place when the error appeared (Upload HTTP Error) because HTTP_USER_AGENT is checked on preDispatch.
In some part of the code, it will call session’s model.
Under this session model, it will validate several things including HTTP_USER_AGENT.
Now I’ll broke down the HTTP_USER_AGENT validation:
Mage_Core_Model_Session_Abstract_Varien
protected function _validate()
{
...
if ($this->useValidateHttpUserAgent()
&& $sessionData[self::VALIDATOR_HTTP_USER_AGENT_KEY] != $validatorData[self::VALIDATOR_HTTP_USER_AGENT_KEY]
&& !in_array($validatorData[self::VALIDATOR_HTTP_USER_AGENT_KEY], $this->getValidateHttpUserAgentSkip())) {
return false;
}
return true;
}
This is the value I got on Mac OSX and Windows:
= Mac OSX =
$sessionData[self::VALIDATOR_HTTP_USER_AGENT_KEY] = Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8) AppleWebKit/536.25 (KHTML, like Gecko) Version/6.0 Safari/536.25
$validatorData[self::VALIDATOR_HTTP_USER_AGENT_KEY] = Adobe Flash Player 11
= Windows =
$sessionData[self::VALIDATOR_HTTP_USER_AGENT_KEY] = Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.83 Safari/537.1
$validatorData[self::VALIDATOR_HTTP_USER_AGENT_KEY] = Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.83 Safari/537.1
= user agent validation skip=
$this->getValidateHttpUserAgentSkip() = Array
(
[0] => Shockwave Flash
[1] => Adobe Flash Player 9
[2] => Adobe Flash Player 10
)
Mage_Core_Model_Session_Abstract
public function getValidateHttpUserAgentSkip()
{
$userAgents = array();
$skip = Mage::getConfig()->getNode(self::XML_NODE_USET_AGENT_SKIP);
foreach ($skip->children() as $userAgent) {
$userAgents[] = (string)$userAgent;
}
return $userAgents;
}
Mage/Core/etc/config.xml
<global>
<session>
<validation>
<http_user_agent_skip>
<flash>Shockwave Flash</flash>
<flash_9_mac>Adobe Flash Player 9</flash_9_mac>
<flash_10_mac>Adobe Flash Player 10</flash_10_mac>
</http_user_agent_skip>
</validation>
</session>
</global>
Mage_Core_Model_Session_Abstract_Varien
public function getValidatorData()
{
...
// collect user agent data
if (isset($_SERVER['HTTP_USER_AGENT'])) {
//(string)$_SERVER['HTTP_USER_AGENT'] on Mac OSX this value is 'Adobe Flash Player 11'
$parts[self::VALIDATOR_HTTP_USER_AGENT_KEY] = (string)$_SERVER['HTTP_USER_AGENT'];
}
return $parts;
}
Testing it on different OS & browser:
= Ubuntu =
Shockwave Flash -> Firefox
Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.75 Safari/537.1 -> Chrome
= Mac OSX =
Adobe Flash Player 11 -> Firefox
Adobe Flash Player 11 -> Safari
Adobe Flash Player 11 -> Chrome
= Windows =
Shockwave Flash -> Firefox
Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.83 Safari/537.1 -> Chrome
Temp fix:
add this line of codes in your config.xml
<global>
<session>
<validation>
<http_user_agent_skip>
<flash_11_mac>Adobe Flash Player 11</flash_11_mac>
</http_user_agent_skip>
</validation>
</session>
</global>
This issue has been fixed in Magento version 1.7.0.0
I’ll update it into Indonesian version later.


