Exemplo n.º 1
0
 /**
  * receive.
  *
  * @method receive
  *
  * @param string   $name
  * @param \Closure $closure
  *
  * @return \Symfony\Component\HttpFoundation\Response;
  */
 public function receive($name, Closure $closure)
 {
     $this->api->setName($name);
     if ($this->api->hasChunks() === false) {
         return $closure($this->api->getFile());
     }
     $resourceName = $this->api->getResourceName();
     $startOffset = $this->api->getStartOffset();
     $partialName = $this->api->getPartialName($this->getChunkPath());
     $this->filesystem->appendStream($resourceName, $partialName, $startOffset);
     if ($this->api->isCompleted() === false) {
         return $this->api->chunkedResponse(new Response(null, 201));
     }
     $originalName = $this->api->getOriginalName();
     $mimeType = $this->api->getMimeType();
     $tmpName = substr($partialName, 0, -5);
     $this->filesystem->move($partialName, $tmpName);
     $file = new UploadedFile($tmpName, $originalName, $mimeType, $this->filesystem->size($tmpName), UPLOAD_ERR_OK, true);
     $response = $closure($file);
     if ($this->filesystem->isFile($tmpName) === true) {
         $this->filesystem->delete($tmpName);
     }
     $response = $this->api->completedResponse($response);
     $this->removeOldData();
     return $response;
 }
Exemplo n.º 2
0
 /**
  * receive.
  *
  * @method receive
  *
  * @param string   $name
  * @param \Closure $closure
  *
  * @return \Symfony\Component\HttpFoundation\Response;
  */
 public function receive($name, Closure $closure)
 {
     $this->api->setName($name);
     if ($this->api->hasChunks() === false) {
         return $closure($this->api->getFile());
     }
     $filesystem = $this->getFilsystem();
     $path = $this->getPath();
     $resource = $this->api->getResource();
     $startOffset = $this->api->getStartOffset();
     $partialName = $path . $this->api->getPartialName();
     $filesystem->updateStream($partialName, $resource, ['startOffset' => $startOffset]);
     if ($this->api->isCompleted() === false) {
         return $this->api->chunkedResponse(new Response(null, 201));
     }
     $originalName = $this->api->getOriginalName();
     $mimeType = $this->api->getMimeType();
     $tmpName = substr($partialName, 0, -5);
     $filesystem->move($partialName, $tmpName);
     $uploadedFile = $this->createUploadedFile($tmpName, $originalName, $mimeType, $filesystem->size($tmpName));
     $response = $closure($uploadedFile);
     if ($filesystem->isFile($tmpName) === true) {
         $filesystem->delete($tmpName);
     }
     $response = $this->api->completedResponse($response);
     $this->removeOldData($path, $this->maxFileAge);
     return $response;
 }