1
0

PartFile.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2021-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OCA\DAV\Upload;
  8. use OCA\DAV\Connector\Sabre\Directory;
  9. use Sabre\DAV\Exception\Forbidden;
  10. use Sabre\DAV\IFile;
  11. /**
  12. * This class represents an Upload part which is not present on the storage itself
  13. * but handled directly by external storage services like S3 with Multipart Upload
  14. */
  15. class PartFile implements IFile {
  16. /** @var Directory */
  17. private $root;
  18. /** @var array */
  19. private $partInfo;
  20. public function __construct(Directory $root, array $partInfo) {
  21. $this->root = $root;
  22. $this->partInfo = $partInfo;
  23. }
  24. /**
  25. * @inheritdoc
  26. */
  27. public function put($data) {
  28. throw new Forbidden('Permission denied to put into this file');
  29. }
  30. /**
  31. * @inheritdoc
  32. */
  33. public function get() {
  34. throw new Forbidden('Permission denied to get this file');
  35. }
  36. public function getPath() {
  37. return $this->root->getFileInfo()->getInternalPath() . '/' . $this->partInfo['PartNumber'];
  38. }
  39. /**
  40. * @inheritdoc
  41. */
  42. public function getContentType() {
  43. return 'application/octet-stream';
  44. }
  45. /**
  46. * @inheritdoc
  47. */
  48. public function getETag() {
  49. return $this->partInfo['ETag'];
  50. }
  51. /**
  52. * @inheritdoc
  53. */
  54. public function getSize() {
  55. return $this->partInfo['Size'];
  56. }
  57. /**
  58. * @inheritdoc
  59. */
  60. public function delete() {
  61. $this->root->delete();
  62. }
  63. /**
  64. * @inheritdoc
  65. */
  66. public function getName() {
  67. return $this->partInfo['PartNumber'];
  68. }
  69. /**
  70. * @inheritdoc
  71. */
  72. public function setName($name) {
  73. throw new Forbidden('Permission denied to rename this file');
  74. }
  75. /**
  76. * @inheritdoc
  77. */
  78. public function getLastModified() {
  79. return $this->partInfo['LastModified'];
  80. }
  81. }