stream video from struts2 action multiple contentType?

前端 未结 1 429
轮回少年
轮回少年 2020-12-12 04:07

I am trying to play video file, for my action contentType is set to

application/octet-stream

now if i change it to audio/mpeg, t

1条回答
  •  离开以前
    2020-12-12 04:20

    Of course you can.

    You must output the Stream Result type from your Action, and specify a parametric contentType, for example:

    Struts.xml

    
      ${yourContentType}
      inputStream
      attachment;filename="${yourFileName}"
      1024
    
    

    Action

    @Getter @Setter private InputStream inputStream;
    @Getter private String yourContentType;
    @Getter private String yourFileName;
    
    public String execute() throws Exception {
    
       yourContentType = "audio/mpeg";
       yourFileName = "yourStuff.mp3";
       byte[] yourContent = loadTheContentInSomeWay();
    
       setInputStream(new ByteArrayInputStream(yourContent));        
    
       return SUCCESS;
    }
    

    You can parameterize the contentDisposition part to specify when a file must be opened as attachment (ask for download) or inline (open in browser) according to your needs.

    0 讨论(0)
提交回复
热议问题