classes/Tools/MediaUpload/UploadTool.php
private function prepareUpload() {
		if(!current_user_can('upload_files')) {
			json_response(["status" => "error", "message" => "Current user can't upload."]);
		}

		if (!$this->client || !$this->client->enabled()) {
			json_response(["status" => "error", "message" => "Storage settings are invalid."]);
		}

		$filename = $_POST['filename'];
		$type = $_POST['type'];

		if (empty($filename) || empty($type)) {
			json_response(["status" => "error", "message" => "Invalid file name or missing type."]);
		}

		$prefix = StorageSettings::prefix(null);
		$parts = explode('/', $filename);
		$bucketFilename = array_pop($parts);

		$uploadInfo = $this->client->uploadUrl($prefix.$bucketFilename,StorageSettings::privacy(), $type,StorageSettings::cacheControl(), StorageSettings::expires());
		$res = $uploadInfo->toArray();
		$res['status'] = 'ready';
		json_response($res);
	}
private function prepareUpload() {
		if(!current_user_can('upload_files')) {
			json_response(["status" => "error", "message" => "Current user can't upload."]);
		}

		if (!$this->client || !$this->client->enabled()) {
			json_response(["status" => "error", "message" => "Storage settings are invalid."]);
		}

		$filename = $_POST['filename'];
		$type = $_POST['type'];

		if (empty($filename) || empty($type)) {
			json_response(["status" => "error", "message" => "Invalid file name or missing type."]);
		}

		$prefix = StorageSettings::prefix(null);
		$parts = explode('/', $filename);
		$bucketFilename = array_pop($parts);

		$uploadInfo = $this->client->uploadUrl($prefix.$bucketFilename,StorageSettings::privacy(), $type,StorageSettings::cacheControl(), StorageSettings::expires());
		$res = $uploadInfo->toArray();
		$res['status'] = 'ready';
		json_response($res);
	}
private function prepareUpload ( ) { if ( ! current_user_can ( 'upload_files' ) ) { json_response ( [ "status" => "error" , "message" => "Current user can't upload." ] ) ; } if ( ! $ this -> client || ! $ this -> client -> enabled ( ) ) { json_response ( [ "status" => "error" , "message" => "Storage settings are invalid." ] ) ; } $ filename = $ _POST [ 'filename' ] ; $ type = $ _POST [ 'type' ] ; if ( empty ( $ filename ) || empty ( $ type ) ) { json_response ( [ "status" => "error" , "message" => "Invalid file name or missing type." ] ) ; } $ prefix = StorageSettings :: prefix ( null ) ; $ parts = explode ( '/' , $ filename ) ; $ bucketFilename = array_pop ( $ parts ) ; $ uploadInfo = $ this -> client -> uploadUrl ( $ prefix . $ bucketFilename , StorageSettings :: privacy ( ) , $ type , StorageSettings :: cacheControl ( ) , StorageSettings :: expires ( ) ) ; $ res = $ uploadInfo -> toArray ( ) ; $ res [ 'status' ] = 'ready' ; json_response ( $ res ) ; }
Called when ready to upload to the storage service
Called when ready to upload to the storage service