PartFile.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. public function __construct(
  17. private Directory $root,
  18. private array $partInfo,
  19. ) {
  20. }
  21. /**
  22. * @inheritdoc
  23. */
  24. public function put($data) {
  25. throw new Forbidden('Permission denied to put into this file');
  26. }
  27. /**
  28. * @inheritdoc
  29. */
  30. public function get() {
  31. throw new Forbidden('Permission denied to get this file');
  32. }
  33. public function getPath() {
  34. return $this->root->getFileInfo()->getInternalPath() . '/' . $this->partInfo['PartNumber'];
  35. }
  36. /**
  37. * @inheritdoc
  38. */
  39. public function getContentType() {
  40. return 'application/octet-stream';
  41. }
  42. /**
  43. * @inheritdoc
  44. */
  45. public function getETag() {
  46. return $this->partInfo['ETag'];
  47. }
  48. /**
  49. * @inheritdoc
  50. */
  51. public function getSize() {
  52. return $this->partInfo['Size'];
  53. }
  54. /**
  55. * @inheritdoc
  56. */
  57. public function delete() {
  58. $this->root->delete();
  59. }
  60. /**
  61. * @inheritdoc
  62. */
  63. public function getName() {
  64. return $this->partInfo['PartNumber'];
  65. }
  66. /**
  67. * @inheritdoc
  68. */
  69. public function setName($name) {
  70. throw new Forbidden('Permission denied to rename this file');
  71. }
  72. /**
  73. * @inheritdoc
  74. */
  75. public function getLastModified() {
  76. return $this->partInfo['LastModified'];
  77. }
  78. }