Manipuler un fichier temporaire

Créez, modifiez, supprimez des fichiers temporaires

Le service TempFileService expose les opérations suivantes :

  • create : pour créer un fichier temporaire
  • getContent : pour récupérer un fichier temporaire
  • delete : pour supprimer un fichier temporaire

Création d’un fichier temporaire

Les exemples suivants définissent comment créer un fichier temporaire.


CREATE:


# <CORE_HOST>  URL de base de FlowerDocs Core
# <TOKEN>      jeton d'authentification

curl -X POST "<CORE_HOST>/rest/files/tmp" \
  -H "token: <TOKEN>" \
  -F "file=@/chemin/vers/fichier"

@Autowired
private TempFileService tempFileService;

public DocumentFile create() throws TechnicalException, FunctionalException
{
    DocumentFile file = new DocumentFile();
    file.setId(new Id("MyFile"));
    file.setContent(new DataHandler(new FileDataSource(File.createTempFile("/tmp", ".txt"))));
    return tempFileService.create(file);
}

Récupération d’un fichier temporaire

Les exemples suivants définissent comment récupérer un fichier temporaire.


GET CONTENT:


# <CORE_HOST>  URL de base de FlowerDocs Core
# <TOKEN>      jeton d'authentification
# <FILE_ID>    identifiant du fichier temporaire

curl -X GET "<CORE_HOST>/rest/files/tmp/<FILE_ID>" \
  -H "token: <TOKEN>"

@Autowired
private TempFileService tempFileService;

public DocumentFile get() throws TechnicalException, FunctionalException
{
    Id id = new Id("MyFile");
    return tempFileService.get(id);
}

Suppression d’un fichier temporaire

Les exemples suivants définissent comment supprimer un fichier temporaire.


DELETE :


# <CORE_HOST>  URL de base de FlowerDocs Core
# <TOKEN>      jeton d'authentification
# <FILE_ID>    identifiant du fichier temporaire

curl -X DELETE "<CORE_HOST>/rest/files/tmp/<FILE_ID>" \
  -H "token: <TOKEN>"

@Autowired
private TempFileService tempFileService;

public void delete() throws TechnicalException, FunctionalException
{
    Id id = new Id("MyFile");
    return tempFileService.delete(id);
}