Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Image 在位于主目录的web上显示图像_Image_Tomcat_Spring Mvc_Nginx_Upload - Fatal编程技术网

Image 在位于主目录的web上显示图像

Image 在位于主目录的web上显示图像,image,tomcat,spring-mvc,nginx,upload,Image,Tomcat,Spring Mvc,Nginx,Upload,我的项目是SpringMVC,运行tomcat7和nginx。 我将用户添加的所有多媒体上传到/home/multimedia 我想从那里向用户展示多媒体。我该怎么办 我找到了一个PHP解决方案,但它没有回答我的问题 使用核心java从磁盘读取图像并保存在BuffereImage中的代码 public BufferedImage savetiff(File srcFilePath) throws IOException { FileSeekableStream stream =

我的项目是SpringMVC,运行tomcat7和nginx。 我将用户添加的所有多媒体上传到/home/multimedia

我想从那里向用户展示多媒体。我该怎么办

我找到了一个PHP解决方案,但它没有回答我的问题


使用核心java从磁盘读取图像并保存在BuffereImage中的代码

public BufferedImage savetiff(File srcFilePath) throws IOException {
        FileSeekableStream stream = new FileSeekableStream(srcFilePath);
        TIFFDecodeParam decodeParam = new TIFFDecodeParam();

        decodeParam.setDecodePaletteAsShorts(true);
        ParameterBlock params = new ParameterBlock();

        params.add(stream);
        RenderedOp image1 = JAI.create("tiff", params);
        BufferedImage img = image1.getAsBufferedImage();

        return img;
}

你可以走两条路。前者的开销最小。如果需要可配置的位置,则第二种方法更方便

1.使用Nginx提供静态文件 创建目标目录的别名

location /media {
    alias /home/multimedia;
    expires 1y;
}
2.使用SpringMVC提供静态文件 您可以使用SpringMVC配置指向文件系统上该目录的静态资源

使用Java配置:

@Configuration
public class ServletConfig extends WebMvcConfigurationSupport {
    @Override
    protected void addResourceHandlers(final ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/media/**")
                .addResourceLocations("file:/home/multimedia/")
                .setCachePeriod(31556926);
    }
}
或在dispatcher servlet.XML中的XML配置,例如:

<mvc:resources location="file:/home/multimedia" mapping="/media/**" cache-period="31556926" />


这不是这个问题的解决方案。@您提供的egemen php链接是用来读取图像的,所以我给了您这段代码。
如果您想这样做,请在src中调用控制器类,返回类型应为图像。我已经使用用于captacha图像的servlet完成了这项工作。创建一个名为ServletConfig并超过这些代码的类就足够了吗?不,这取决于您使用的是基于Java还是基于XML的配置。上述课程是前者的一部分。我还向答案中添加了资源的XML配置。