gpt4 book ai didi

java - 如何将图像存储到 jackrabbit 并将这些图像传送到 HTML 页面?

转载 作者:行者123 更新时间:2023-11-30 07:07:56 24 4
gpt4 key购买 nike

如何将图像存储到 jackrabbit 并将这些图像传送到 HTML 页面?前任。如果用户将从一个 HTML 页面上传多个图像,那么他应该能够在需要时在下一个 html 页面或任何其他页面中看到所有这些图像

最佳答案

是这样的:

 public class JackRabbitServiceImpl {

Repository repository = new TransientRepository();

public JackRabbitServiceImpl() throws Exception{
Session session = repository.login(
new SimpleCredentials("username", "password".toCharArray()));
try{
InputStream stream = new BufferedInputStream(JackRabbitServiceImpl.class.getResourceAsStream("red_rose.jpg"));
Node folder = session.getRootNode();
Node file = folder.addNode("redrose.jpg","nt:file");
Node content = file.addNode("jcr:content","nt:resource");
Binary binary = session.getValueFactory().createBinary(stream);
content.setProperty("jcr:data",binary);
content.setProperty("jcr:mimeType","image/gif");
session.save();
}finally{
session.logout();
}
}

public byte[] getContentRose() throws Exception{
Session session = repository.login(
new SimpleCredentials("username", "password".toCharArray()));
Node folder = session.getRootNode();
Node file=folder.getNode("redrose.jpg");
Node content=file.getNode("jcr:content");
String path = content.getPath();
Binary bin = session.getNode(path).getProperty("jcr:data").getBinary();
InputStream stream = bin.getStream();
return IOUtils.toByteArray(stream);
}

}

小服务程序

public class TestJackRabbitCdn extends HttpServlet {

/**
*
*/
private static final long serialVersionUID = 4158924623219324725L;
JackRabbitServiceImpl service=null;
@Override
public void init(){
try {
service=new JackRabbitServiceImpl();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException,
ServletException {
response.setContentType("image/gif");
try {
response.getOutputStream().write(service.getContentRose());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
response.getOutputStream().flush();
}

}

关于java - 如何将图像存储到 jackrabbit 并将这些图像传送到 HTML 页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24394609/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com