| @@ 121-142 (lines=22) @@ | ||
| 118 | /** |
|
| 119 | * {@inheritdoc} |
|
| 120 | */ |
|
| 121 | public function write($path, $contents, Config $config) |
|
| 122 | { |
|
| 123 | $object = $this->applyPathPrefix($path); |
|
| 124 | $options = $this->getOptions([], $config); |
|
| 125 | ||
| 126 | if (!isset($options[OssClient::OSS_LENGTH])) { |
|
| 127 | $options[OssClient::OSS_LENGTH] = Util::contentSize($contents); |
|
| 128 | } |
|
| 129 | if (!isset($options[OssClient::OSS_CONTENT_TYPE])) { |
|
| 130 | $options[OssClient::OSS_CONTENT_TYPE] = Util::guessMimeType($path, $contents); |
|
| 131 | } |
|
| 132 | ||
| 133 | try { |
|
| 134 | // https://help.aliyun.com/document_detail/31978.html |
|
| 135 | $this->client->putObject($this->bucket, $object, $contents, $options); |
|
| 136 | } catch (OssException $e) { |
|
| 137 | $this->logErr(__FUNCTION__, $e); |
|
| 138 | return false; |
|
| 139 | } |
|
| 140 | ||
| 141 | return $this->normalizeResponse($options, $path); |
|
| 142 | } |
|
| 143 | ||
| 144 | /** |
|
| 145 | * {@inheritdoc} |
|
| @@ 166-186 (lines=21) @@ | ||
| 163 | /** |
|
| 164 | * {@inheritdoc} |
|
| 165 | */ |
|
| 166 | public function writeFile($path, $filePath, Config $config) |
|
| 167 | { |
|
| 168 | $object = $this->applyPathPrefix($path); |
|
| 169 | $options = $this->getOptions([], $config); |
|
| 170 | ||
| 171 | if (!isset($options[OssClient::OSS_CONTENT_TYPE])) { |
|
| 172 | $options[OssClient::OSS_CHECK_MD5] = true; |
|
| 173 | } |
|
| 174 | if (!isset($options[OssClient::OSS_CONTENT_TYPE])) { |
|
| 175 | $options[OssClient::OSS_CONTENT_TYPE] = Util::guessMimeType($path, ''); |
|
| 176 | } |
|
| 177 | ||
| 178 | try { |
|
| 179 | $this->client->uploadFile($this->bucket, $object, $filePath, $options); |
|
| 180 | } catch (OssException $e) { |
|
| 181 | $this->logErr(__FUNCTION__, $e); |
|
| 182 | return false; |
|
| 183 | } |
|
| 184 | ||
| 185 | return $this->normalizeResponse($options, $path); |
|
| 186 | } |
|
| 187 | ||
| 188 | /** |
|
| 189 | * {@inheritdoc} |
|