fopen s3 objects directly to work around unexplainable guzzle bug
For some reason when a text file started with a valid hex character ([0-9a-f]) it would eat the text untill the first newline The new code does basically the same thing as guzzle/s3-sdk did only without wrapping everything in a guzzle stream Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
parent
eb21dc2bd3
commit
3ab160dd5a
1 changed files with 21 additions and 30 deletions
|
@ -21,11 +21,6 @@
|
||||||
|
|
||||||
namespace OC\Files\ObjectStore;
|
namespace OC\Files\ObjectStore;
|
||||||
|
|
||||||
use Guzzle\Http\EntityBody;
|
|
||||||
use Guzzle\Http\Message\RequestInterface;
|
|
||||||
use Guzzle\Service\Command\CommandInterface;
|
|
||||||
use Guzzle\Stream\PhpStreamRequestFactory;
|
|
||||||
use Icewind\Streams\CallbackWrapper;
|
|
||||||
use OCP\Files\ObjectStore\IObjectStore;
|
use OCP\Files\ObjectStore\IObjectStore;
|
||||||
|
|
||||||
// TODO: proper composer
|
// TODO: proper composer
|
||||||
|
@ -48,20 +43,6 @@ class S3 implements IObjectStore {
|
||||||
return $this->id;
|
return $this->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Serialize and sign a command, returning a request object
|
|
||||||
*
|
|
||||||
* @param CommandInterface $command Command to sign
|
|
||||||
*
|
|
||||||
* @return RequestInterface
|
|
||||||
*/
|
|
||||||
protected function getSignedRequest($command) {
|
|
||||||
$request = $command->prepare();
|
|
||||||
$request->dispatch('request.before_send', array('request' => $request));
|
|
||||||
|
|
||||||
return $request;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $urn the unified resource name used to identify the object
|
* @param string $urn the unified resource name used to identify the object
|
||||||
* @return resource stream with the read data
|
* @return resource stream with the read data
|
||||||
|
@ -70,20 +51,30 @@ class S3 implements IObjectStore {
|
||||||
*/
|
*/
|
||||||
function readObject($urn) {
|
function readObject($urn) {
|
||||||
// Create the command and serialize the request
|
// Create the command and serialize the request
|
||||||
$request = $this->getSignedRequest($this->getConnection()->getCommand('GetObject', [
|
$request = $this->getConnection()->getCommand('GetObject', [
|
||||||
'Bucket' => $this->bucket,
|
'Bucket' => $this->bucket,
|
||||||
'Key' => $urn
|
'Key' => $urn
|
||||||
]));
|
])->prepare();
|
||||||
// Create a stream that uses the EntityBody object
|
|
||||||
$factory = new PhpStreamRequestFactory();
|
|
||||||
/** @var EntityBody $body */
|
|
||||||
$body = $factory->fromRequest($request, array(), array('stream_class' => 'Guzzle\Http\EntityBody'));
|
|
||||||
$stream = $body->getStream();
|
|
||||||
|
|
||||||
// we need to keep the guzzle request in scope untill the stream is closed
|
$request->dispatch('request.before_send', array(
|
||||||
return CallbackWrapper::wrap($stream, null, null, function () use ($body) {
|
'request' => $request
|
||||||
$body->close();
|
));
|
||||||
});
|
|
||||||
|
$headers = $request->getHeaderLines();
|
||||||
|
$headers[] = 'Connection: close';
|
||||||
|
|
||||||
|
$opts = [
|
||||||
|
'http' => [
|
||||||
|
'method' => "GET",
|
||||||
|
'header' => $headers
|
||||||
|
],
|
||||||
|
'ssl' => [
|
||||||
|
'verify_peer' => true
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
$context = stream_context_create($opts);
|
||||||
|
return fopen($request->getUrl(), 'r', false, $context);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue