lundi 30 août 2021

When opening file via Servlet, it returns files but has a issue about filename

My code here:

@GET
@Path("getFile")
public Response getFile(@QueryParam("accessKey") String accessKey) throws Exception {
    File file = new File(accessKey);

    //Getting filename
    String fileName = file.getName();

    // Response
    return Response.ok((Object) file).header("Content-Type", "application/vnd.ms-powerpoint")
            .header("Content-Disposition: inline;", " filename*=\"" + fileName + "\"")
            .header("Content-Lentgh", file.length())
            .build();
}

This code works well, but the title bar of opened file says "getFile.pptx". This is not actual filename , I think this is action name of this method or a part of URL I accessed. How can I fix this to get right file name? I don't wanna change this part, "Content-Disposition: inline;" because I want to open file directly, not attaching.




Aucun commentaire:

Enregistrer un commentaire