/** * Append a chunk to a temporary file (not attached to any artifact) * * Use this method to append a file chunk to any existing file created via POST on /artifact_temporary_files * <ol> * <li>This method cannot be called on a file that is already referenced by an artifact * </li> * <li>The offset property is used by the server in order to detect error in the consistency of the data * uploaded but it is not possible to upload chunks in the wrong order * </li> * <li>Only the user who created the temporary artifact_file can modify and view that file until it is attached to an artifact * </li> * </ol> * * @url PUT {id} * * @param int $id The ID of the temporary artifact_file * @param string $content Chunk of the file (base64-encoded) {@from body} * @param int $offset Used to check that the chunk uploaded is the next one (minimum value is 2) {@from body} * * @return \Tuleap\Tracker\REST\Artifact\FileInfoRepresentation * @throws 406 */ protected function putId($id, $content, $offset) { $this->checkFileIsTemporary($id); $file = $this->getFile($id); try { $this->file_manager->validateChunkSize($this->user, $content); $this->file_manager->appendChunk($content, $file, $offset); } catch (ChunkTooBigException $e) { $this->raiseError(406, 'Uploaded content exceeds maximum size of ' . $this->file_manager->getMaximumChunkSize()); } catch (InvalidOffsetException $e) { $this->raiseError(406, 'Invalid offset received. Expected: ' . ($file->getCurrentChunkOffset() + 1)); } catch (QuotaExceededException $e) { $this->raiseError(406, 'You exceeded your quota. Please remove existing temporary files before continuing.'); } $this->sendAllowHeadersForArtifactFilesId(); return $this->buildFileRepresentation($file); }
/** * Append a chunk to a temporary file (not attached to any artifact) * * Use this method to append a file chunk to any existing file created via POST on /artifact_temporary_files * <ol> * <li>This method cannot be called on a file that is already referenced by an artifact * </li> * <li>The offset property is used by the server in order to detect error in the consistency of the data * uploaded but it is not possible to upload chunks in the wrong order * </li> * <li>Only the user who created the temporary artifact_file can modify and view that file until it is attached to an artifact * </li> * </ol> * * @url PUT {id} * * @param int $id The ID of the temporary artifact_file * @param string $content Chunk of the file (base64-encoded) {@from body} * @param int $offset Used to check that the chunk uploaded is the next one (minimum value is 2) {@from body} * * @return \Tuleap\Tracker\REST\Artifact\FileInfoRepresentation * @throws 406 */ protected function putId($id, $content, $offset) { $this->sendAllowHeadersForArtifactFilesId(); $this->checkFileIsTemporary($id); $file = $this->getFile($id); try { $this->file_manager->validateChunkSize($content); $this->file_manager->validateTemporaryFileSize($file, $content); $this->file_manager->appendChunk($content, $file, $offset); } catch (ChunkTooBigException $e) { throw new RestException(406, 'Uploaded content exceeds maximum size of ' . FileManager::getMaximumChunkSize()); } catch (TemporaryFileTooBigException $e) { throw new RestException(406, "Temporary file's content exceeds maximum size of " . FileManager::getMaximumTemporaryFileSize()); } catch (InvalidOffsetException $e) { throw new RestException(406, 'Invalid offset received. Expected: ' . ($file->getCurrentChunkOffset() + 1)); } return $this->buildFileRepresentation($file); }