Qual è il modo migliore per gestire l'eliminazione di un file dopo che è stato restituito come risposta a una richiesta REST?Come eliminare il file dopo la risposta REST
Ho un endpoint che crea un file su richiesta e lo restituisce nella risposta. Una volta che la risposta è stata inviata, il file non è più necessario e può/deve essere rimosso.
@Path("file")
@GET
@Produces({MediaType.APPLICATION_OCTET_STREAM})
@Override
public Response getFile() {
// Create the file
...
// Get the file as a steam for the entity
File file = new File("the_new_file");
ResponseBuilder response = Response.ok((Object) file);
response.header("Content-Disposition", "attachment; filename=\"the_new_file\"");
return response.build();
// Obviously I can't do this but at this point I need to delete the file!
}
Immagino di poter creare un file tmp ma avrei pensato che esistesse un meccanismo più elegante per raggiungere questo obiettivo. Il file potrebbe essere abbastanza grande, quindi non posso caricarlo in memoria.
Non sicuro perché il voto negativo! – tarka