| @@ 16-37 (lines=22) @@ | ||
| 13 | /** |
|
| 14 | * {@inheritdoc} |
|
| 15 | */ |
|
| 16 | public function write($path, $contents, Config $config) |
|
| 17 | { |
|
| 18 | $object = $this->applyPathPrefix($path); |
|
| 19 | $options = $this->getOptions([], $config); |
|
| 20 | ||
| 21 | if (!isset($options[OssClient::OSS_LENGTH])) { |
|
| 22 | $options[OssClient::OSS_LENGTH] = Util::contentSize($contents); |
|
| 23 | } |
|
| 24 | if (!isset($options[OssClient::OSS_CONTENT_TYPE])) { |
|
| 25 | $options[OssClient::OSS_CONTENT_TYPE] = Util::guessMimeType($path, $contents); |
|
| 26 | } |
|
| 27 | ||
| 28 | try { |
|
| 29 | // https://help.aliyun.com/document_detail/31978.html |
|
| 30 | $this->client->putObject($this->bucket, $object, $contents, $options); |
|
| 31 | } catch (OssException $e) { |
|
| 32 | $this->logErr(__FUNCTION__, $e); |
|
| 33 | return false; |
|
| 34 | } |
|
| 35 | ||
| 36 | return $this->normalizeResponse($options, $path); |
|
| 37 | } |
|
| 38 | ||
| 39 | /** |
|
| 40 | * {@inheritdoc} |
|
| @@ 61-81 (lines=21) @@ | ||
| 58 | /** |
|
| 59 | * {@inheritdoc} |
|
| 60 | */ |
|
| 61 | public function writeFile($path, $filePath, Config $config) |
|
| 62 | { |
|
| 63 | $object = $this->applyPathPrefix($path); |
|
| 64 | $options = $this->getOptions([], $config); |
|
| 65 | ||
| 66 | if (!isset($options[OssClient::OSS_CONTENT_TYPE])) { |
|
| 67 | $options[OssClient::OSS_CHECK_MD5] = true; |
|
| 68 | } |
|
| 69 | if (!isset($options[OssClient::OSS_CONTENT_TYPE])) { |
|
| 70 | $options[OssClient::OSS_CONTENT_TYPE] = Util::guessMimeType($path, ''); |
|
| 71 | } |
|
| 72 | ||
| 73 | try { |
|
| 74 | $this->client->uploadFile($this->bucket, $object, $filePath, $options); |
|
| 75 | } catch (OssException $e) { |
|
| 76 | $this->logErr(__FUNCTION__, $e); |
|
| 77 | return false; |
|
| 78 | } |
|
| 79 | ||
| 80 | return $this->normalizeResponse($options, $path); |
|
| 81 | } |
|
| 82 | ||
| 83 | /** |
|
| 84 | * {@inheritdoc} |
|