在Spring 3中将图像文件上载到其他服务器

时间:2014-06-12 13:11:20

标签: java spring spring-mvc file-upload

伙计们,我有一个问题可能听起来像之前已经解决但不是!!

我正在尝试使用Spring MVC 3将图像从D驱动器上传到服务器。 但是,当我尝试将文件从驱动器D复制到驱动器C时,它的工作原理! 例如: - 从我的http://localhost:8080/loadImage加载图片并浏览要加载到http://q.someimagerepository.com/的图片 代码: -

InputStream inputStream = null;
OutputStream outputStream = null;
inputStream = helloFile.getInputStream();
outputStream = new FileOutputStream("http://q.someimagerepository.com/newImage");
int readBytes = 0;
byte[] buffer = new byte[10000];
while ((readBytes = inputStream.read(buffer, 0, 10000)) != -1) {
outputStream.write(buffer, 0, readBytes);
}
outputStream.close();
inputStream.close();

其中helloFIle(CommonsMultipartFile文件)是我浏览并选择后从屏幕加载的文件。 我们还必须发送文件扩展名吗?

我不确定我做错了什么。我收到的错误如下: -

(文件名,目录名或卷标语法不正确)

请告诉我这样做的正确方法。 此外,当我尝试将文件从驱动器D复制到驱动器C时,以下代码可以正常工作,但不适用于上述情况: -

//Correct approach in SPRING
helloFile.transferTo(new File("C:/"));

2 个答案:

答案 0 :(得分:0)

将“C:”的图像移动到“D:”或www.webpage.com/app以在服务器上移动“C:”?

问候。

答案 1 :(得分:0)

我认为我们必须包含服务器类型的JAR文件。 使用jar文件 - 打开http连接 - 将数据(本例中的图像)添加到输入流 - 使用输出流写入数据。

Connection.put(IMAGEURL,.....)

花了一段时间,但我们得到了它。感谢Stackoverflow团队的回复。

此致 LE