public function execute()
    {
        try {
            $result = $this->uploader->saveFileToTmpDir($this->getFieldName());

            $result['cookie'] = [
                'name' => $this->_getSession()->getName(),
                'value' => $this->_getSession()->getSessionId(),
                'lifetime' => $this->_getSession()->getCookieLifetime(),
                'path' => $this->_getSession()->getCookiePath(),
                'domain' => $this->_getSession()->getCookieDomain(),
            ];
        } catch (\Exception $e) {
            $result = ['error' => $e->getMessage(), 'errorcode' => $e->getCode()];
        }
        return $this->resultFactory->create(ResultFactory::TYPE_JSON)->setData($result);
    }
public function execute()
    {
        try {
            $result = $this->uploader->saveFileToTmpDir($this->getFieldName());

            $result['cookie'] = [
                'name' => $this->_getSession()->getName(),
                'value' => $this->_getSession()->getSessionId(),
                'lifetime' => $this->_getSession()->getCookieLifetime(),
                'path' => $this->_getSession()->getCookiePath(),
                'domain' => $this->_getSession()->getCookieDomain(),
            ];
        } catch (\Exception $e) {
            $result = ['error' => $e->getMessage(), 'errorcode' => $e->getCode()];
        }
        return $this->resultFactory->create(ResultFactory::TYPE_JSON)->setData($result);
    }
public function execute ( ) { try { $ result = $ this -> uploader -> saveFileToTmpDir ( $ this -> getFieldName ( ) ) ; $ result [ 'cookie' ] = [ 'name' => $ this -> _getSession ( ) -> getName ( ) , 'value' => $ this -> _getSession ( ) -> getSessionId ( ) , 'lifetime' => $ this -> _getSession ( ) -> getCookieLifetime ( ) , 'path' => $ this -> _getSession ( ) -> getCookiePath ( ) , 'domain' => $ this -> _getSession ( ) -> getCookieDomain ( ) , ] ; } catch ( \ Exception $ e ) { $ result = [ 'error' => $ e -> getMessage ( ) , 'errorcode' => $ e -> getCode ( ) ] ; } return $ this -> resultFactory -> create ( ResultFactory :: TYPE_JSON ) -> setData ( $ result ) ; }
Upload file controller action

@return \Magento\Framework\Controller\ResultInterface
Upload file controller action