/** * @inheritdoc */ public function writeStream($path, $resource, Config $config) { $size = Util::getStreamSize($resource); list(, $err) = $this->streamUpload($path, $resource, $size); if ($err !== null) { return false; } return compact('size', 'path'); }
/** * Upload an object. * * @param $path * @param $body * @param Config $config * * @return array */ protected function upload($path, $body, Config $config) { $key = $this->applyPathPrefix($path); $options = $this->getOptionsFromConfig($config); $acl = isset($options['ACL']) ? $options['ACL'] : 'private'; if (!isset($options['ContentType']) && is_string($body)) { $options['ContentType'] = Util::guessMimeType($path, $body); } if (!isset($options['ContentLength'])) { $options['ContentLength'] = is_string($body) ? Util::contentSize($body) : Util::getStreamSize($body); } $this->s3Client->upload($this->bucket, $key, $body, $acl, ['params' => $options]); return $this->normalizeResponse($options, $key); }
/** * @inheritdoc */ public function updateStream($path, $resource, Config $config) { $size = Util::getStreamSize($resource); $resumeUploader = new ResumeUploader($this->getUploadToken(), $path, $resource, $size, null, 'application/octet-stream'); list(, $err) = $resumeUploader->upload(); if ($err !== null) { return false; } return compact('size', 'path'); }
/** * Update a file using a stream * * @param string $path * @param resource $resource * @param mixed $config Config object or visibility setting * @return array|bool */ public function updateStream($path, $resource, Config $config) { $size = Util::getStreamSize($resource); list($ret, $err) = Qiniu_RS_Rput($this->getClient(), $this->bucket, $path, $resource, $size, null); if ($err !== null) { return false; } return compact('size', 'path'); }
/** * {@inheritdoc} */ public function writeStream($path, $resource, Config $config) { $options = $this->getOptions($path, ['Content' => $resource, 'ContentType' => Util::guessMimeType($path, $resource), 'ContentLength' => Util::getStreamSize($resource)], $config); if ($this->client->putObject($options) === false) { return false; } return true; }
/** * {@inheritdoc} */ public function writeStream($path, $resource, Config $config) { $options = ['Body' => $resource]; $options['ContentLength'] = Util::getStreamSize($resource); $options = $this->getOptions($path, $options, $config); return $this->writeObject($options); }
/** * Upload an object. * * @param $path * @param $body * @param Config $config * * @return array */ protected function upload($path, $body, Config $config) { $options = $this->getOptionsFromConfig($config); $response = null; try { if (is_string($body)) { $response = $this->client->putObjectFromString($this->bucket, $path, $body, $options); } else { if (is_resource($body)) { if (isset($options['file'])) { $file = $options['file']; } else { $metadata = stream_get_meta_data($body); $file = $metadata['uri']; } if ($file !== null) { $response = $this->client->putObjectFromFile($this->bucket, $path, $file, $options); } else { if (!isset($options[BosOptions::CONTENT_TYPE])) { } if (!isset($options[BosOptions::CONTENT_LENGTH])) { $contentLength = Util::getStreamSize($body); } else { $contentLength = $options[BosOptions::CONTENT_LENGTH]; unset($options[BosOptions::CONTENT_LENGTH]); } if (!isset($options[BosOptions::CONTENT_MD5])) { $contentMd5 = base64_encode(HashUtils::md5FromStream($body, 0, $contentLength)); } else { $contentMd5 = $options[BosOptions::CONTENT_MD5]; unset($options[BosOptions::CONTENT_MD5]); } $response = $this->client->putObject($this->bucket, $path, $body, $contentLength, $contentMd5, $options); if (is_resource($body)) { fclose($body); } } } else { throw new \InvalidArgumentException("{$body} type should be string or resource"); } } } catch (BceBaseException $e) { if (stcmp(gettype($e), "BceClientException") == 0) { $this->logger->debug("BceClientException: " . $e->getMessage()); } if (stcmp(gettype($e), "BceServerException") == 0) { $this->logger->debug("BceServerException: " . $e->getMessage()); } if (is_resource($body)) { fclose($body); } return false; } catch (\InvalidArgumentException $e) { $this->logger->debug("InvalidArgumentException: " . $e->getMessage()); if (is_resource($body)) { fclose($body); } return false; } catch (\Exception $e) { $this->logger->debug("Exception: " . $e->getMessage()); if (is_resource($body)) { fclose($body); } return false; } return $this->normalizeResponse($response->metadata, $path); }
/** * Do the actual upload of a file resource. * * @param string $path * @param resource $resource * @param WriteMode $mode * * @return array|false file metadata */ protected function uploadStream($path, $resource, WriteMode $mode) { $location = $this->applyPathPrefix($path); // If size is zero, consider it unknown. $size = Util::getStreamSize($resource) ?: null; if (!($result = $this->client->uploadFile($location, $mode, $resource, $size))) { return false; } return $this->normalizeResponse($result, $path); }
/** * Write using a stream * * @param string $path * @param resource $resource * @param mixed $config ['visibility'='private', 'mimetype'='', 'Metadata'=[]] * * @return array file metadata */ public function writeStream($path, $resource, $config = null) { $config = Util::ensureConfig($config); $options = array('Body' => $resource); $options['ContentLength'] = Util::getStreamSize($resource); $options = $this->getOptions($path, $options, $config); return $this->writeObject($options); }
/** * @inheritdoc */ public function updateStream($path, $resource, Config $config) { $size = Util::getStreamSize($resource); $result = $this->streamUpload($path, $resource, $size); if ($result !== null) { return false; } return compact('size', 'path'); }
/** * Build the request * * @param array $options * @return RequestBuilder */ public function build($options) { $this->endpoint = $options['endpoint']; $this->headers['Date'] = gmdate('D, d M Y H:i:s \\G\\M\\T'); if (isset($this->body)) { if (is_resource($this->body)) { $this->headers['Content-Length'] = Util::getStreamSize($this->body); } else { $this->headers['Content-Length'] = strlen($this->body); } $this->headers['Content-Md5'] = base64_encode($this->getMD5($this->body)); if (isset($options['Content-Type'])) { $this->headers['Content-Type'] = $options['Content-Type']; } else { $this->headers['Content-Type'] = $this->getMimeType($this->path, $this->body); } } else { $this->headers['Content-Md5'] = ''; $this->headers['Content-Type'] = ''; } $this->headers['Host'] = $options['host']; ksort($this->oss_headers); foreach ($this->oss_headers as $k => $v) { $this->headers[$k] = $v; } if (!isset($this->bucket)) { $this->path = '/'; } else { $this->path = '/' . $this->bucket . '/' . $this->path; } ksort($this->params); ksort($this->overrides); $query = array_merge($this->params, $this->overrides); $query_str = http_build_query($query); if (!empty($query_str)) { $this->query = '?' . $query_str; $this->query = str_replace('acl=', 'acl', $this->query); } ksort($this->headers); $sign = new Signature($this); $this->headers['Authorization'] = 'OSS ' . $options['access_id'] . ':' . $sign->create($options['access_key']); return $this; }
/** * {@inheritdoc} */ public function writeStream($path, $resource, Config $config) { $bucket = $this->bucket; $options = $this->getOptions($this->options, $config); $multipartLimit = $this->mbToBytes($options['Multipart']); $size = Util::getStreamSize($resource); $contents = fread($resource, $size); if ($size > $multipartLimit) { printf(__FUNCTION__ . ": OVER LIMIT\n"); printf($e->getMessage() . "\n"); return; } else { try { $this->client->putObject($bucket, $path, $contents, $options); } catch (OssException $e) { printf(__FUNCTION__ . ": FAILED\n"); printf($e->getMessage() . "\n"); return; } } }
public function writeStreamWithoutKey($resource, Config $config) { $size = Util::getStreamSize($resource); $token = $config->get('token'); return $this->streamUpload(null, $resource, $size, 'application/octet-stream', null, $token); }