Change fragment handling strategy for empty files
Signed-off-by: Bernd.Rederlechner@t-systems.com <bernd.rederlechner@t-systems.com>
This commit is contained in:
parent
828dde4453
commit
7d3b5956e4
|
@ -97,40 +97,36 @@ trait S3ObjectTrait {
|
||||||
$count += $read;
|
$count += $read;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$s3params = [
|
||||||
|
'bucket' => $this->bucket,
|
||||||
|
'key' => $urn,
|
||||||
|
'part_size' => $this->uploadPartSize,
|
||||||
|
'params' => [
|
||||||
|
'ContentType' => $mimetype
|
||||||
|
] + $this->getSseKmsPutParameters(),
|
||||||
|
];
|
||||||
|
|
||||||
if ($count === 0 && feof($countStream)) {
|
// maybe, we should also use ObjectUploader here in the future
|
||||||
// This is an empty file so just touch it then
|
// it does direct uploads for small files < 5MB and multipart otherwise
|
||||||
$s3params = [
|
// $uploader = new ObjectUploader($this->getConnection(), $this->bucket, $urn, $countStream, 'private', $s3params);
|
||||||
'params' => $this->getSseKmsPutParameters(),
|
$uploader = new MultipartUploader($this->getConnection(), $countStream, $s3params);
|
||||||
];
|
|
||||||
$uploader = new ObjectUploader($this->getConnection(), $this->bucket, $urn, '', 'private', $s3params);
|
|
||||||
} else {
|
|
||||||
$s3params = [
|
|
||||||
'bucket' => $this->bucket,
|
|
||||||
'key' => $urn,
|
|
||||||
'part_size' => $this->uploadPartSize,
|
|
||||||
'params' => [
|
|
||||||
'ContentType' => $mimetype
|
|
||||||
] + $this->getSseKmsPutParameters(),
|
|
||||||
];
|
|
||||||
|
|
||||||
// maybe, we should also use ObjectUploader here in the future
|
|
||||||
// it does direct uploads for small files < 5MB and multipart otherwise
|
|
||||||
// $uploader = new ObjectUploader($this->getConnection(), $this->bucket, $urn, $countStream, 'private', $s3params);
|
|
||||||
$uploader = new MultipartUploader($this->getConnection(), $countStream, $s3params);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$uploader->upload();
|
$uploader->upload();
|
||||||
} catch (S3MultipartUploadException $e) {
|
} catch (S3MultipartUploadException $e) {
|
||||||
// if anything goes wrong with multipart, make sure that you don´t poison s3 bucket with fragments
|
// if anything goes wrong with multipart, make sure that you don´t poison s3 bucket with fragments
|
||||||
$this->getConnection()->abortMultipartUpload([
|
$this->getConnection()->abortMultipartUpload($uploader->getState()->getId());
|
||||||
'Bucket' => $this->bucket,
|
|
||||||
'Key' => $urn,
|
if ($count === 0 && feof($countStream)) {
|
||||||
'UploadId' => $uploader->getState()->getId()
|
// This is an empty file case, so just touch it
|
||||||
]);
|
$s3params = [
|
||||||
|
'params' => $this->getSseKmsPutParameters(),
|
||||||
throw $e;
|
];
|
||||||
|
$uploader = new ObjectUploader($this->getConnection(), $this->bucket, $urn, '', 'private', $s3params);
|
||||||
|
$uploader->upload();
|
||||||
|
} else {
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
// this handles [S3] fclose(): supplied resource is not a valid stream resource #23373
|
// this handles [S3] fclose(): supplied resource is not a valid stream resource #23373
|
||||||
// see https://stackoverflow.com/questions/11247507/fclose-18-is-not-a-valid-stream-resource/11247555
|
// see https://stackoverflow.com/questions/11247507/fclose-18-is-not-a-valid-stream-resource/11247555
|
||||||
|
|
Loading…
Reference in New Issue