PartFile.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Lukas Reschke <lukas@statuscode.ch>
  7. * @author Thomas Müller <thomas.mueller@tmit.eu>
  8. *
  9. * @license AGPL-3.0
  10. *
  11. * This code is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License, version 3,
  13. * as published by the Free Software Foundation.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License, version 3,
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>
  22. *
  23. */
  24. namespace OCA\DAV\Upload;
  25. use OCA\DAV\Connector\Sabre\Directory;
  26. use Sabre\DAV\Exception\Forbidden;
  27. use Sabre\DAV\IFile;
  28. /**
  29. * This class represents an Upload part which is not present on the storage itself
  30. * but handled directly by external storage services like S3 with Multipart Upload
  31. */
  32. class PartFile implements IFile {
  33. /** @var Directory */
  34. private $root;
  35. /** @var array */
  36. private $partInfo;
  37. public function __construct(Directory $root, array $partInfo) {
  38. $this->root = $root;
  39. $this->partInfo = $partInfo;
  40. }
  41. /**
  42. * @inheritdoc
  43. */
  44. public function put($data) {
  45. throw new Forbidden('Permission denied to put into this file');
  46. }
  47. /**
  48. * @inheritdoc
  49. */
  50. public function get() {
  51. throw new Forbidden('Permission denied to get this file');
  52. }
  53. public function getPath() {
  54. return $this->root->getFileInfo()->getInternalPath() . '/' . $this->partInfo['PartNumber'];
  55. }
  56. /**
  57. * @inheritdoc
  58. */
  59. public function getContentType() {
  60. return 'application/octet-stream';
  61. }
  62. /**
  63. * @inheritdoc
  64. */
  65. public function getETag() {
  66. return $this->partInfo['ETag'];
  67. }
  68. /**
  69. * @inheritdoc
  70. */
  71. public function getSize() {
  72. return $this->partInfo['Size'];
  73. }
  74. /**
  75. * @inheritdoc
  76. */
  77. public function delete() {
  78. $this->root->delete();
  79. }
  80. /**
  81. * @inheritdoc
  82. */
  83. public function getName() {
  84. return $this->partInfo['PartNumber'];
  85. }
  86. /**
  87. * @inheritdoc
  88. */
  89. public function setName($name) {
  90. throw new Forbidden('Permission denied to rename this file');
  91. }
  92. /**
  93. * @inheritdoc
  94. */
  95. public function getLastModified() {
  96. return $this->partInfo['LastModified'];
  97. }
  98. }