Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/329.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
Java 如何使用REST将图像从iOS应用程序上载到服务器?_Java_Rest_Spring Mvc - Fatal编程技术网

Java 如何使用REST将图像从iOS应用程序上载到服务器?

Java 如何使用REST将图像从iOS应用程序上载到服务器?,java,rest,spring-mvc,Java,Rest,Spring Mvc,我使用spring作为控制器。如何实现此功能。 我试过Base64解码器和编码器,但它只允许小图像。还有其他的想法或建议吗。我会非常感激的 I want to upload image from iOS app. and store into server's folder. 这是我的控制器。请指导我。POST asmultipart/form data谢谢,但如何在控制器中获取该图像并存储在服务器文件夹中。http:/localhost:8080/www.mydomain.com/mypr

我使用spring作为控制器。如何实现此功能。 我试过Base64解码器和编码器,但它只允许小图像。还有其他的想法或建议吗。我会非常感激的

I want to upload image from iOS app. and store into server's folder. 

这是我的控制器。请指导我。

POST as
multipart/form data
谢谢,但如何在控制器中获取该图像并存储在服务器文件夹中。http:/localhost:8080/www.mydomain.com/myproject/Customer/uploadImage.htm当我在POST man中测试时,它会给我一个404错误请求。请帮帮我。你不能只发到像http://code>localhost:8080/www.mydomain.com/myproject/Customer/uploadImage.htm这样的东西上——这需要映射为REST端点。您的
uploadImage()
方法中有@POST注释吗?我建议您通过
https://spring.io/guides/gs/uploading-files/
,看看你是否能完成这项工作。谢谢你抽出时间。我没有在该方法中使用@POST注释。图像将从iOS应用程序上传,我需要使用spring控制器存储在服务器上。如果您有其他想法,请指导。-Johannes JanderPOST as
multipart/form data
谢谢,但如何在控制器中获取该映像并存储在服务器文件夹中。http:/localhost:8080/www.mydomain.com/myproject/Customer/uploadImage.htm当我在Post man中测试时,它会给我一个404错误请求。请帮帮我。你不能只发到像http://code>localhost:8080/www.mydomain.com/myproject/Customer/uploadImage.htm这样的东西上——这需要映射为REST端点。您的
uploadImage()
方法中有@POST注释吗?我建议您通过
https://spring.io/guides/gs/uploading-files/
,看看你是否能完成这项工作。谢谢你抽出时间。我没有在该方法中使用@POST注释。图像将从iOS应用程序上传,我需要使用spring控制器存储在服务器上。如果您有其他想法,请指导。-约翰内斯·詹德
@RequestMapping(value="Customer/uploadImage.htm",
        method = RequestMethod.POST)
@ResponseBody
public String uploadImage(@RequestParam("file") MultipartFile file) {
    String filePath = HomeAppUtil.getPathForImage();
    System.out.println("filepath "+filePath);
    String img = "testfile.jpeg";
    try {
        // parses the request's content to extract file data
        if(file.getSize() !=0){
            System.out.println("in if");
            File fileToCreate = new File(filePath, img);
            System.out.println("in if 1");
            if (!fileToCreate.exists()) {
                System.out.println("in if 2");
                FileUtils.writeByteArrayToFile(fileToCreate, file.getBytes());
                System.out.println("in if 3");
            }
        }

    } catch (Exception ex) {
        ex.printStackTrace();

    }


    JSONArray jsonArray = new JSONArray();
    jsonArray.put("updated or fialed!!");

    return jsonArray.toString();
}