Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable15] always use multipart uploader for s3 uploads #13882

Merged
merged 1 commit into from
Jan 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/private/Files/ObjectStore/S3ObjectTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

namespace OC\Files\ObjectStore;

use Aws\S3\MultipartUploader;
use Aws\S3\S3Client;

const S3_UPLOAD_PART_SIZE = 524288000; // 500MB
Expand Down Expand Up @@ -72,10 +73,12 @@ function readObject($urn) {
* @since 7.0.0
*/
function writeObject($urn, $stream) {
$this->getConnection()->upload($this->bucket, $urn, $stream, 'private', [
'mup_threshold' => S3_UPLOAD_PART_SIZE,
$uploader = new MultipartUploader($this->getConnection(), $stream, [
'bucket' => $this->bucket,
'key' => $urn,
'part_size' => S3_UPLOAD_PART_SIZE
]);
$uploader->upload();
}

/**
Expand Down
31 changes: 28 additions & 3 deletions tests/lib/Files/ObjectStore/S3Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

namespace Test\Files\ObjectStore;

use Icewind\Streams\Wrapper;
use OC\Files\ObjectStore\S3;

class MultiPartUploadS3 extends S3 {
Expand All @@ -31,6 +32,30 @@ function writeObject($urn, $stream) {
}
}

class NonSeekableStream extends Wrapper {
public static function wrap($source) {
$context = stream_context_create(array(
'nonseek' => array(
'source' => $source
)
));
return Wrapper::wrapSource($source, $context, 'nonseek', self::class);
}

public function dir_opendir($path, $options) {
return false;
}

public function stream_open($path, $mode, $options, &$opened_path) {
$this->loadContext('nonseek');
return true;
}

public function stream_seek($offset, $whence = SEEK_SET) {
return false;
}
}

/**
* @group PRIMARY-s3
*/
Expand All @@ -44,15 +69,15 @@ protected function getInstance() {
return new S3($config['arguments']);
}

public function testMultiPartUploader() {
public function testUploadNonSeekable() {
$config = \OC::$server->getConfig()->getSystemValue('objectstore');
if (!is_array($config) || $config['class'] !== 'OC\\Files\\ObjectStore\\S3') {
$this->markTestSkipped('objectstore not configured for s3');
}

$s3 = new MultiPartUploadS3($config['arguments']);
$s3 = $this->getInstance();

$s3->writeObject('multiparttest', fopen(__FILE__, 'r'));
$s3->writeObject('multiparttest', NonSeekableStream::wrap(fopen(__FILE__, 'r')));

$result = $s3->readObject('multiparttest');

Expand Down