Uploads a snap.

@todo
Fix media ID generation; it looks like they're GUIDs now.

@param int $type
The media type, i.e. MEDIA_IMAGE or MEDIA_VIDEO.
@param data $data
The file data to upload.

@return mixed
The ID of the uploaded media or FALSE on failure.
10659
public function upload($type, $data) {
		// Make sure we're logged in and have a valid access token.
		if (!$this->auth_token || !$this->username) {
			return FALSE;
		}

		// To make cURL happy, we write the data to a file first.
		$temp = tempnam(sys_get_temp_dir(), 'Snap');
		file_put_contents($temp, parent::encryptECB($data));

		if (version_compare(PHP_VERSION, '5.5.0', '>=')) {
			$cfile = curl_file_create($temp, ($type == self::MEDIA_IMAGE ? 'image/jpeg' : 'video/quicktime'), 'snap');
		}

		$media_id = strtoupper($this->username) . '~' . time();
		$timestamp = parent::timestamp();
		$result = parent::post(
			'/upload',
			array(
				'media_id' => $media_id,
				'type' => $type,
				'data' => (version_compare(PHP_VERSION, '5.5.0', '>=') ? $cfile : '@' . $temp . ';filename=data'),
				'timestamp' => $timestamp,
				'username' => $this->username,
			),
			array(
				$this->auth_token,
				$timestamp,
			),
			TRUE
		);

		unlink($temp);

		return is_null($result) ? $media_id : FALSE;
	}
840500
public function createMediaImage(array $data = [])
    {
        $type  = $this->resolveImageType(array_key_exists('image_type', $data) ? $data['image_type'] : null);
        $image = $this->hydrate($type, $data);

        if (array_key_exists('media', $data) && array_key_exists('media_type', $data)) {
            switch ($data['media_type']) {
                case "movie":
                    $factory = new MovieFactory($this->getHttpClient());
                    break;

                case "tv":
                    $factory = new TvFactory($this->getHttpClient());
                    break;
                    
                case "season":
                    $factory = new TvSeasonFactory($this->getHttpClient());
                    break;
                    
                // I don't think this ever occurs, but just in case..
                case "episode":
                    $factory = new TvEpisodeFactory($this->getHttpClient());
                    break;

                // I don't think this ever occurs, but just in case..
                case "person":
                    $factory = new PeopleFactory($this->getHttpClient());
                    break;

                default:
                    throw new RuntimeException(sprintf(
                        'Unrecognized media_type "%s" for method "%s::%s".',
                        $data['media_type'],
                        __CLASS__,
                        __METHOD__
                    ));
            }

            $media = $factory->create($data['media']);

            $image->setMedia($media);
        }

        return $image;
    }
469928
public function uploadImage(string $path, string $type = 'icon')
    {
        if (!file_exists($path) || !is_readable($path)) {
            throw new InvalidArgumentException(sprintf('File does not exist, or the file is unreadable: "%s"', $path));
        }

        return $this->httpUpload('shakearound/material/add', ['media' => $path], [], ['type' => strtolower($type)]);
    }
5372
public function setImageType($type)
	{
		if ($type)
		{
			$this->image_type = $type;
		}

		if ($this->image_type == IMAGETYPE_PNG && $this->resource)
		{
			imagealphablending($this->resource, false);
			imagesavealpha($this->resource, true);
		}
	}
398845
public function log($type = null, $data = [])
    {
        if (!func_num_args()) {
            return $this->_log;
        }
        $this->report($type, $this->log()->add($type, $data));
    }
1179154
protected function uploadChunk($uri, $data)
    {
        $response = $this->client->request(
            'POST',
            $uri,
            [
                'headers' => [
                    'Content-Length' => strlen($data),
                    'Content-Type'   => 'application/octet-stream',
                ],
                'body' => $data,
            ]
        );

        return (string) $response->getBody();
    }
90177
public function add($filename, $type = 'image')
    {
        if (!in_array($type, ['image', 'voice', 'video', 'thumb'])) {
            throw new InvalidResponseException('Invalid Media Type.', '0');
        }
        $url = "https://api.weixin.qq.com/cgi-bin/media/upload?access_token=ACCESS_TOKEN&type={$type}";
        $this->registerApi($url, __FUNCTION__, func_get_args());
        return $this->httpPostForJson($url, ['media' => Tools::createCurlFile($filename)], false);
    }
1060058
public function upload(array $data)
    {
        $content = $this->readCSV($data);
        if ($content === false) {
            return false;
        }

        $return = $this->writeFile($data['locale'], $content, 'csv');
        if ($return === false) {
            return false;
        }

        return $this->activeTranslate($data['locale']);

    }
576798
public function onFrame($data, $type)
    {
        if (!isset($this->route)) {
            return false;
        }
        try {
            $this->route->onWakeup();
            $this->route->onFrame($data, $type);
        } catch (\Exception $e) {
            Daemon::uncaughtExceptionHandler($e);
        }
        if ($this->route) {
            $this->route->onSleep();
        }
        return true;
    }
272914
private function saveFile($data) {
		$fileupload = \Yii::createObject(\Yii::$app->components[$this->fileupload]);
		$fileinfo = $fileupload->createFile($data['extension']);
		$file = fopen($fileinfo['tmp'], 'wb');
		fwrite($file, $data['content']);
		fclose($file);

		return $fileupload->finalFile($fileinfo);
	}
1220690
public function createNew($data)
    {
        if ($data instanceof File) {
            /** @var $data File */
            $media = new Media();
            if (method_exists($data, 'getClientOriginalName')) {
                $media->setOriginalFilename($data->getClientOriginalName());
            } else {
                $media->setOriginalFilename($data->getFilename());
            }
            $media->setContent($data);

            $contentType = $this->mimeTypeGuesser->guess($media->getContent()->getPathname());
            $media->setContentType($contentType);

            return $media;
        }

        return null;
    }
1066613
public function upload($data)
    {
        if (!isset($data['image'])) {
            throw new MissingArgumentException(['image']);
        }

        $typeValues = ['file', 'base64', 'url'];
        if (isset($data['type']) && !\in_array(strtolower($data['type']), $typeValues, true)) {
            throw new InvalidArgumentException('Type parameter "' . $data['type'] . '" is wrong. Possible values are: ' . implode(', ', $typeValues));
        }

        if ('file' === $data['type']) {
            $data['image'] = '@' . $data['image'];
        }

        return $this->post('image', $data);
    }
1357928
public function getAPIByType($type)
    {
        switch ($type) {
            case 'news_image':
                $api = self::API_NEWS_IMAGE_UPLOAD;
                break;
            default:
                $api = self::API_UPLOAD;
        }

        return $api;
    }
870221
public static function data($data, $type = null)
    {
        $type === null && $type = MongoBinData::BYTE_ARRAY;

        return new MongoBinData($data, $type);
    }
461463
protected function _create(array $data, $type, $id = null, array $parameters = []) {
        return $this->__create($data, $this->index(), $type, $id, $parameters);
    }
1205135
public function write($data)
    {

        if (is_resource($data)) {
            return (bool)stream_copy_to_stream($data, $this->resource());
        }

        $isStream = $data instanceof Stream;

        if (!$isStream && Type::isStringable($data)) {
            return (bool)fwrite($this->resource(), $data);
        }

        if (!$isStream) {
            throw new TypeException('Unsupported data type in write(): ' . Type::of($data));
        }

        $dataResource = $data->resource();

        if (is_resource($dataResource)) {
            return $this->write($dataResource);
        }

        $resource = $this->resource();

        $bytes = 0;

        foreach ($data as $chunk) {
            $bytes += fwrite($resource, $chunk);
        }

        return (bool)$bytes;

    }
834415
public function build( $data = null, $type = null ) {

		if ( ! empty( $data ) ) {
			$this->set_data( $data );
		}

		if ( ! empty( $type ) && in_array( $type, $this->types, true ) ) {
			$this->type = $type;
		}

		if ( method_exists( $this, "build_{$this->type}" ) ) {
			call_user_func( array( $this, 'build_' . $this->type ) );
		}

		return $this->data;
	}