Mistake:

07-24 07:11:05.903 15734-15734/com.project.samuliak.psychogram E/samuliak: Upload error:java.io.FileNotFoundException: /external/images/media/725: open failed: ENOENT (No such file or directory) 

I choose a picture from the gallery, then send it to the server. But in the log here is such a mistake. Request:

  Call<String> call = service.uploadFile(descriptionString, body); call.enqueue(new Callback<String>() { @Override public void onResponse(Call<String> call, Response<String> response) { path[0] = response.body(); Log.e("samuliak", "Succesful:"+response.body()); } @Override public void onFailure(Call<String> call, Throwable t) { Log.e("samuliak", "Upload error:"+t.toString()); } }); 

retrofit api:

 // Загрузка фото @Multipart @POST("psychologist/upload") Call<String> uploadFile(@Part("description") String description, @Part MultipartBody.Part file); 

The controller on the server that receives the file:

  /* Загрузка фото (!) */ @RequestMapping(value="/psychologist/upload", method=RequestMethod.POST) @ResponseBody public String uploadFile(@RequestParam("name") String name, @RequestParam("file") MultipartFile file){ if (!file.isEmpty()) { String path = ""; try { byte[] bytes = file.getBytes(); path = new File(name + "-uploaded").getPath(); System.out.println(path); BufferedOutputStream stream = new BufferedOutputStream(new FileOutputStream(new File(name + "-uploaded"))); stream.write(bytes); stream.close(); return path; } catch (Exception e) { System.out.println("Вам не удалось загрузить " + name + " => " + e.getMessage()); return "Вам не удалось загрузить " + name + " => " + e.getMessage(); } } else { return "Вам не удалось загрузить " + name + " потому что файл пустой."; } } 

Help!

UPDATE

Spring, the method in the controller does not work correctly

  • do you have permission to read external? What version of Android? - Vladyslav Matviienko
  • Yes, there is permission. Android 5.1 - Samuliak
  • Although at the moment I fixed this error. But the problem is from the server, here is a link to a new question: added to the main post - Samuliak

0