summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@users.noreply.github.com>2019-02-18 15:39:17 +0100
committerGitHub <noreply@github.com>2019-02-18 15:39:17 +0100
commitf6f002e2ad46f7eb48c3e7a131236be5466a239a (patch)
treea2da71aa5772da3c9b9999a7bbe40cc10c52ea23 /lib
parent49e8093e15fb0626f32002da7cf73b7789f1a7d4 (diff)
parentfc967a5ac2dee93376685d4fe9faababafe55491 (diff)
downloadnextcloud-server-f6f002e2ad46f7eb48c3e7a131236be5466a239a.tar.gz
nextcloud-server-f6f002e2ad46f7eb48c3e7a131236be5466a239a.zip
Merge pull request #14210 from nextcloud/fix/14192/fix_empty_uploads
Fix empty file uploads to S3 (and other streaming storages)
Diffstat (limited to 'lib')
-rw-r--r--lib/private/Files/ObjectStore/S3ObjectTrait.php25
1 files changed, 23 insertions, 2 deletions
diff --git a/lib/private/Files/ObjectStore/S3ObjectTrait.php b/lib/private/Files/ObjectStore/S3ObjectTrait.php
index 0b55c319ea8..7c46ba25c11 100644
--- a/lib/private/Files/ObjectStore/S3ObjectTrait.php
+++ b/lib/private/Files/ObjectStore/S3ObjectTrait.php
@@ -23,8 +23,11 @@
namespace OC\Files\ObjectStore;
+use Aws\S3\Exception\S3MultipartUploadException;
use Aws\S3\MultipartUploader;
+use Aws\S3\ObjectUploader;
use Aws\S3\S3Client;
+use Icewind\Streams\CallbackWrapper;
const S3_UPLOAD_PART_SIZE = 524288000; // 500MB
@@ -73,12 +76,30 @@ trait S3ObjectTrait {
* @since 7.0.0
*/
function writeObject($urn, $stream) {
- $uploader = new MultipartUploader($this->getConnection(), $stream, [
+ $count = 0;
+ $countStream = CallbackWrapper::wrap($stream, function ($read) use (&$count) {
+ $count += $read;
+ });
+
+ $uploader = new MultipartUploader($this->getConnection(), $countStream, [
'bucket' => $this->bucket,
'key' => $urn,
'part_size' => S3_UPLOAD_PART_SIZE
]);
- $uploader->upload();
+
+ try {
+ $uploader->upload();
+ } catch (S3MultipartUploadException $e) {
+ // This is an emty file so just touch it then
+ if ($count === 0 && feof($countStream)) {
+ $uploader = new ObjectUploader($this->getConnection(), $this->bucket, $urn, '');
+ $uploader->upload();
+ } else {
+ throw $e;
+ }
+ }
+
+ fclose($countStream);
}
/**