Upload a file on the Dailymotion servers and generate an URL to be used with API methods.

@param String $filePath    a path to the file to upload
@param String $oauth_token a path to the file to upload

@return String the resulting URL
169452
public function sendFile($filePath, $oauth_token)
    {
        $result = $this->call('file.upload', [], $oauth_token);
        $timeout = $this->timeout;
        $this->timeout = null;
        $result = json_decode($this->httpRequest($result['upload_url'], ['file' => '@' . $filePath]), true);
        $this->timeout = $timeout;

        return $result['url'];
    }
870879
public function upload($bucket, $filePath, $key = null){
        $response = $this->uploadToken($bucket, $key);
        if(!$response['success']){
            return $response;
        }
        $uploadToken = $response['data'];
        return $this->uploadWithToken($uploadToken, $filePath, $key);
    }
697501
public function uploadShopImage($filePath, $fileName = null)
    {
        $fileName === null && $fileName = pathinfo($filePath, PATHINFO_BASENAME);
        $result = $this->httpRaw(self::WECHAT_SHOP_IMAGE_UPLOAD_URL .
            'access_token=' . $this->getAccessToken() . '&filename=' . $fileName, file_get_contents($filePath));
        return isset($result['errmsg']) && $result['errmsg'] == 'success' ? $result['image_url'] : false;
    }
832381
public function uploadFile($file_path)
    {
        if ( ! is_file($file_path)) {
            throw new EasemobError('文件不存在', 404);
        }
        $url = $this->url.'chatfiles';

        $curl_file    = curl_file_create($file_path);
        $option       = [
            'file' => $curl_file,
        ];
        $access_token = $this->getToken();
        $header []    = 'Authorization: Bearer '.$access_token;

        return Http::postCurl($url, $option, $header, 'POST');
    }
743252
public static function getStationFile($stationFtpPath, $outputPath)
    {
        $ftpConfig = DWDConfiguration::getFTPConfiguration();

        $ftp_connection = ftp_connect($ftpConfig->url);

        $login_result = ftp_login($ftp_connection, $ftpConfig->userName, $ftpConfig->userPassword);
        if ($login_result && ftp_size($ftp_connection, $stationFtpPath) > -1) {
            $result = ftp_get($ftp_connection, $outputPath, $stationFtpPath, FTP_BINARY);
//            DWDUtil::log(self::class, "out=" . $outputPath);
//            DWDUtil::log(self::class, "ftp=" . $stationFtpPath);
            ftp_close($ftp_connection);

            if (!isset($result)) {
                throw new DWDLibException("Could not retrieve data from ftp location: " . $stationFtpPath);
            }
        }

    }
774778
protected function createNonreusableSignature($bucket, $filepath)
    {
        if (preg_match('/^\//', $filepath) == 0) {
            $filepath = '/' . $filepath;
        }

        $fileId = '/' . $this->config->get('app_id') . '/' . $bucket . $filepath;

        return $this->createSignature(0, $bucket, $fileId);
    }
1284140
def upload(self, file_path, description=None, async=False):
        
        url = "documents?async={a}".format(a=async)
        return self.core.upload(file_path, url, description)
1071705
private static function uploadFile($bucket, $srcPath, $dstPath, $bizAttr = null, $insertOnly = null) {
        $srcPath = realpath($srcPath);
	    $dstPath = self::cosUrlEncode($dstPath);

	    if (filesize($srcPath) >= self::MAX_UNSLICE_FILE_SIZE ) {
		    return array(
                'code' => COSAPI_PARAMS_ERROR,
                'message' => 'file '.$srcPath.' larger then 20M, please use uploadBySlicing interface',
                'data' => array()
            );
	    }

        $expired = time() + self::EXPIRED_SECONDS;
        $url = self::generateResUrl($bucket, $dstPath);
        $signature = Auth::createReusableSignature($expired, $bucket);
        $fileSha = hash_file('sha1', $srcPath);

        $data = array(
            'op' => 'upload',
            'sha' => $fileSha,
            'biz_attr' => (isset($bizAttr) ? $bizAttr : ''),
        );

        $data['filecontent'] = file_get_contents($srcPath);

        if (isset($insertOnly) && strlen($insertOnly) > 0) {
            $data['insertOnly'] = (($insertOnly == 0 || $insertOnly == '0' ) ? 0 : 1);
        }

        $req = array(
            'url' => $url,
            'method' => 'post',
            'timeout' => self::$timeout,
            'data' => $data,
            'header' => array(
                'Authorization: ' . $signature,
            ),
        );

        return self::sendRequest($req);
    }
375772
public function writeToFile($filePath)
    {
        $out = @fopen($filePath,"w");

        if (!$out){
            throw new AssetException($this->token,
                "The asset '".$this->token."' could not be written to path '$filePath'. Check the path is valid and the directory exists.");
        }

        $stream = $this->getStream();

        if (!$stream){
            throw new AssetException($this->token,
                "The asset '".$this->token."' could not provide a valid stream.'");
        }

        while(!feof($stream)){
            $bytes = fread($stream, 8192);
            fwrite($out, $bytes);
        }

        fclose($stream);
        fclose($out);
    }
145985
public static function upload($filePath, $bucket, $fileid = '', $userid = 0, $magicContext = '', $params = array()) {
        if (!file_exists($filePath)) {
            return array('httpcode' => 0, 'code' => self::IMAGE_FILE_NOT_EXISTS, 'message' => 'file '.$filePath.' not exists', 'data' => array());
        }

        return self::upload_impl($filePath, 0, $bucket, $fileid, $userid, $magicContext, $params);
    }
238506
public static function fromKeyFile($firebaseURI, $keyFile, $rootPath = '/')
    {
        return new self($firebaseURI, OAuth::fromKeyFile($keyFile), $rootPath);
    }
981617
public function createStreamingResponse($filePath, $fileName, $type = 'application/octet-stream')
    {
        $response = new StreamedResponse();
        $this->setStreamCallBack($response, $filePath);
        $this->setStreamHeaders($response, $fileName, $type);

        return $response;
    }
324233
private static Optional<Token<?>> getTokenFromSeqFile(String authPath, String proxyUserName) throws IOException {
    try (Closer closer = Closer.create()) {
      FileSystem localFs = FileSystem.getLocal(new Configuration());
      SequenceFile.Reader tokenReader =
          closer.register(new SequenceFile.Reader(localFs, new Path(authPath), localFs.getConf()));
      Text key = new Text();
      Token<?> value = new Token<>();
      while (tokenReader.next(key, value)) {
        LOG.info("Found token for " + key);
        if (key.toString().equals(proxyUserName)) {
          return Optional.<Token<?>> of(value);
        }
      }
    }
    return Optional.absent();
  }
421878
protected function createThumbnail($imagePath, $thumbnailPath) {
        if ($this->config['images']['thumbnail']['enabled'] === true) {
            Log::info('generating thumbnail "' . $thumbnailPath . '"');

            // create folder if it does not exist
            if (!file_exists(dirname($thumbnailPath))) {
                mkdir(dirname($thumbnailPath), 0755, true);
            }

            $this->initUploader([
                'upload_dir' => dirname($imagePath) . '/',
            ])->create_thumbnail_image($imagePath);
        }
    }
865786
protected function createWritableStream ($filePath)
    {
        if (is_resource($filePath)) {
            $stream = $filePath;
        } elseif (is_string($filePath)) {
            $stream = fopen($filePath, 'wb');
            if (! $stream) {
                throw new InvalidArgumentException("Can't open file `{$filePath}` for writing.");
            }
        } else {
            $stream = tmpfile();
        }

        return $stream;
    }
749905
protected function loadClientSecretFromFile(string $filePath)
    {
        $this->logger->info('Getting the Google API client secret from the `'.$filePath.'` file');

        try {
            $secretData = $this->loadCredentialJSON($filePath);
        } catch (\RuntimeException $exception) {
            throw new \RuntimeException('Couldn\'t parse the client secret file: '.$exception->getMessage());
        }

        try {
            $this->client->setAuthConfig($secretData);
        } catch (\Exception $exception) {
            throw new \RuntimeException('Failed to apply the client secret from file `'.$filePath.'` to Google SDK: '.$exception->getMessage());
        }
    }
267818
public static function getFileUrl($filePath, $addTimestamp = FALSE) {

		if (!file_exists($filePath)) {
			throw new \Exception('File not found at path ' . $filePath);
		}
		
		// check if valid path
		if (FALSE === strpos($filePath, APPLICATION_PATH)) {
			throw new \Exception('File path doesn’t match the application root folder ' . APPLICATION_PATH);
		}
		
		// BASE_HREF has trailing slash
		$url = BASE_HREF . substr($filePath, strlen(APPLICATION_PATH)+1);
			
		if ($addTimestamp) {
			$timestamp = filemtime($filePath);
			// check if valid timestamp
			if (FALSE == $timestamp) {
				throw new \Exception('File last change timestamp failed for ' . $filePath);
			}
			$url .= '?' . $timestamp;
		}
		
		return $url;

	}