diff --git a/Entity/Repository/UploadedFileRepository.php b/Entity/Repository/UploadedFileRepository.php
index 592e4d36da6b06b716806982d559e47620a021e8..b2c1888dfc30776e0cc6937ba0e77708467d963e 100644
--- a/Entity/Repository/UploadedFileRepository.php
+++ b/Entity/Repository/UploadedFileRepository.php
@@ -10,6 +10,8 @@ namespace Irstea\FileUploadBundle\Entity\Repository;
 use DateTime;
 use Doctrine\ORM\EntityRepository;
 use Gaufrette\Filesystem;
+use Gaufrette\StreamMode;
+use InvalidArgumentException;
 use Irstea\FileUploadBundle\Entity\UploadedFile;
 use Irstea\FileUploadBundle\Event\FileUploadCompleteEvent;
 use Irstea\FileUploadBundle\Exception\RejectedFileException;
@@ -17,9 +19,9 @@ use Irstea\FileUploadBundle\FileUploadEvents;
 use Irstea\FileUploadBundle\Model\FileManagerInterface;
 use Irstea\FileUploadBundle\Model\UploadedFileInterface;
 use Psr\Log\LogLevel;
+use Rhumsaa\Uuid\Uuid;
 use Symfony\Component\EventDispatcher\EventDispatcher;
 use Symfony\Component\EventDispatcher\EventDispatcherInterface;
-use Rhumsaa\Uuid\Uuid;
 
 /**
  * Description of UploadedFileRepository
@@ -87,7 +89,7 @@ class UploadedFileRepository extends EntityRepository implements FileManagerInte
     public function duplicate(UploadedFileInterface $original)
     {
         if (!$original->isValid()) {
-            throw new \InvalidArgumentException("Impossible de dupliquer le fichier ".$original->getId()." car il est invalide !");
+            throw new InvalidArgumentException("Impossible de dupliquer le fichier ".$original->getId()." car il est invalide !");
         }
 
         $new = new UploadedFile();
@@ -109,12 +111,11 @@ class UploadedFileRepository extends EntityRepository implements FileManagerInte
             ->setSize($original->getSize());
 
         $stream = $this->filesystem->createStream($new->getPath());
-        $stream->open("cb");
-        $original->copyTo($stream);
+        $stream->open(new StreamMode("cb"));
+        $original->copyTo($stream->cast(STREAM_CAST_AS_STREAM));
         $stream->close();
 
         $this->_em->persist($new);
-        $this->_em->flush();
 
         return $new;
     }
@@ -133,7 +134,7 @@ class UploadedFileRepository extends EntityRepository implements FileManagerInte
             return null;
         }
         if (!is_string($uuid) || !Uuid::isValid($uuid)) {
-            throw new \InvalidArgumentException(sprintf("Identifiant invalide: %s", (string)$uuid));
+            throw new InvalidArgumentException(sprintf("Identifiant invalide: %s", (string)$uuid));
         }
         return $this->findOneById($uuid);
     }