/** * Creates the file $filePath on DFS with content $contents * * @param string $filePath * @param string $contents * * @return bool */ public function createFileOnDFS($filePath, $contents) { try { $this->s3client->upload($this->bucket, $filePath, $contents, 'public-read'); return true; } catch (S3Exception $e) { eZDebug::writeError($e->getMessage(), __METHOD__); return false; } }
/** * Publishes the specified source file to this target, with the given relative path. * * @param resource $sourceStream * @param string $relativeTargetPathAndFilename * @param ResourceMetaDataInterface $metaData * @throws \Exception */ protected function publishFile($sourceStream, $relativeTargetPathAndFilename, ResourceMetaDataInterface $metaData) { $objectName = $this->keyPrefix . $relativeTargetPathAndFilename; $options = array('ContentLength' => $metaData->getFileSize(), 'ContentType' => $metaData->getMediaType()); try { $this->s3Client->upload($this->bucketName, $objectName, $sourceStream, 'public-read', $options); $this->systemLogger->log(sprintf('Successfully published resource as object "%s" in bucket "%s" with MD5 hash "%s"', $objectName, $this->bucketName, $metaData->getMd5() ?: 'unknown'), LOG_DEBUG); } catch (\Exception $e) { $this->systemLogger->log(sprintf('Failed publishing resource as object "%s" in bucket "%s" with MD5 hash "%s": %s', $objectName, $this->bucketName, $metaData->getMd5() ?: 'unknown', $e->getMessage()), LOG_DEBUG); throw $e; } }
/** * 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); }
/** * @param string $fileName * @param string $fileContents * @return ResultInterface */ public function uploadFile($fileName, $fileContents) { return $this->s3Client->upload($this->bucket, $this->basePath . "/" . $fileName, $fileContents); }
/** * @param string $fileExtension * @param string $data * * @return string */ public function store($fileExtension, $data) { /* @var $result \Aws\Result */ $result = $this->s3Client->upload($this->backet, uniqid() . '.' . $fileExtension, $data); return $result->get('ObjectURL'); }
/** * upload * * @param string $key * @param mixed $body * @param string $acl * @param array $options * * @return \Guzzle\Service\Resource\Model */ public function upload($key, $body, $acl = 'private', array $options = array()) { return $this->client->upload($this->name, $key, $body, $acl, $options); }
/** * @param string $remoteFile * @param string $content */ function saveFile($remoteFile, $content) { $this->lastRemoteFile = $remoteFile; $this->s3Client->upload($this->bucket, $remoteFile, $content); }
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch (Exception $e) { echo $e->getMessage(); die; } ?> <html> <head><meta charset="UTF-8"></head> <body> <h1>S3 upload example</h1> <?php if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_FILES['userfile']) && $_FILES['userfile']['error'] == UPLOAD_ERR_OK && is_uploaded_file($_FILES['userfile']['tmp_name'])) { // FIXME: add more validation, e.g. using ext/fileinfo try { // FIXME: do not use 'name' for upload (that's the original filename from the user's computer) $upload = $s3->upload($bucket, $_FILES['userfile']['name'], fopen($_FILES['userfile']['tmp_name'], 'rb'), 'public-read'); ?> <p>Upload <a href="<?php echo htmlspecialchars($upload->get('ObjectURL')); ?> ">successful</a> :)</p> <?php } catch (Exception $e) { ?> <p>Upload error :(</p> <?php } } ?> <h2>Upload a file</h2> <form enctype="multipart/form-data" action="<?php