Handling a temporary file

Create, modify, delete temporary files

The TempFileService service exposes the following operations:

  • create: to create a temporary file
  • getContent: to retrieve a temporary file
  • delete: to delete a temporary file

Creating a temporary file

The following examples show how to create a temporary file.


CREATE:


# <CORE_HOST>  FlowerDocs Core base URL
# <TOKEN>      authentication token

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

@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);
}

Recovering a temporary file

The following examples show how to recover a temporary file.


GET CONTENT:


# <CORE_HOST>  FlowerDocs Core base URL
# <TOKEN>      authentication token
# <FILE_ID>    identifier of the temporary file

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);
}

Deleting a temporary file

The following examples show how to delete a temporary file.


DELETE :


# <CORE_HOST>  FlowerDocs Core base URL
# <TOKEN>      authentication token
# <FILE_ID>    identifier of the temporary file

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);
}