/** * 上传内存中的内容 * * @param string $bucket bucket名称 * @param string $object objcet名称 * @param string $content 上传的内容 * @param array $options * @return null */ public function putObject($bucket, $object, $content, $options = NULL) { $this->precheckCommon($bucket, $object, $options); OssUtil::validateContent($content); $options[self::OSS_CONTENT] = $content; $options[self::OSS_BUCKET] = $bucket; $options[self::OSS_METHOD] = self::OSS_HTTP_PUT; $options[self::OSS_OBJECT] = $object; if (!isset($options[self::OSS_LENGTH])) { $options[self::OSS_CONTENT_LENGTH] = strlen($options[self::OSS_CONTENT]); } else { $options[self::OSS_CONTENT_LENGTH] = $options[self::OSS_LENGTH]; } if (!isset($options[self::OSS_CONTENT_TYPE])) { $options[self::OSS_CONTENT_TYPE] = $this->getMimeType($object); } $response = $this->auth($options); $result = new PutSetDeleteResult($response); return $result->getData(); }
/** * 追加上传内存中的内容 * * @param string $bucket bucket名称 * @param string $object objcet名称 * @param string $content 本次追加上传的内容 * @param array $options * @return int next append position * @throws OssException */ public function appendObject($bucket, $object, $content, $position, $options = NULL) { $this->precheckCommon($bucket, $object, $options); OssUtil::validateContent($content); $options[self::OSS_CONTENT] = $content; $options[self::OSS_BUCKET] = $bucket; $options[self::OSS_METHOD] = self::OSS_HTTP_POST; $options[self::OSS_OBJECT] = $object; $options[self::OSS_SUB_RESOURCE] = 'append'; $options[self::OSS_POSITION] = strval($position); if (!isset($options[self::OSS_LENGTH])) { $options[self::OSS_CONTENT_LENGTH] = strlen($options[self::OSS_CONTENT]); } else { $options[self::OSS_CONTENT_LENGTH] = $options[self::OSS_LENGTH]; } if (!isset($options[self::OSS_CONTENT_TYPE])) { $options[self::OSS_CONTENT_TYPE] = $this->getMimeType($object); } $response = $this->auth($options); $result = new AppendResult($response); return $result->getData(); }
public function testValidContent() { $null = ""; try { OssUtil::validateContent($null); $this->assertTrue(false); } catch (OssException $e) { $this->assertEquals('http body content is invalid', $e->getMessage()); } $notnull = "x"; try { OssUtil::validateContent($notnull); $this->assertTrue(true); } catch (OssException $e) { $this->assertEquals('http body content is invalid', $e->getMessage()); } }