I am sending a photo to the server Shipping Code:
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()); } });
Here is the retrofit API:
@Multipart @POST("psychologist/upload") Call<String> uploadFile(@Part("name") String description, @Part MultipartBody.Part file);
But the controller method:
@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 + " потому что файл пустой."; } }
I understand that the method is incorrectly formed, so please explain to me how to properly! I really want to know this, it's very difficult to figure it out myself and I have been sitting and suffering for 4 hours already! Help!
UPDATE
08-04 13:55:02.670 24439-24439/com.project.samuliak.psychogram E/samuliak: Activity result in Registr.. 08-04 13:55:02.692 24439-24439/com.project.samuliak.psychogram E/samuliak: path from act.result > /storage/emulated/0/DCIM/Camera/IMG_20160624_141505_1.jpg 08-04 13:55:02.705 24439-24454/com.project.samuliak.psychogram I/art: Background partial concurrent mark sweep GC freed 482(34KB) AllocSpace objects, 1(16KB) LOS objects, 39% free, 3MB/6MB, paused 6.386ms total 15.981ms 08-04 13:55:02.711 24439-24451/com.project.samuliak.psychogram W/CursorWrapperInner: Cursor finalized without prior close() 08-04 13:55:02.779 24439-24439/com.project.samuliak.psychogram E/samuliak: uploadFile. End. 08-04 13:55:02.808 24439-24478/com.project.samuliak.psychogram W/EGL_emulation: eglSurfaceAttrib not implemented 08-04 13:55:02.808 24439-24478/com.project.samuliak.psychogram W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xe2026ee0, error=EGL_SUCCESS 08-04 13:55:03.045 24439-24439/com.project.samuliak.psychogram E/samuliak: not succesful > Bad Request 08-04 13:55:03.045 24439-24439/com.project.samuliak.psychogram E/samuliak: body > :null
UPDATE Update Cataline Log
05-Aug-2016 10:42:31.506 INFO [RMI TCP Connection(3)-127.0.0.1] org.hibernate.engine.jdbc.env.internal.LobCreatorBuilderImpl.useContextualLobCreation HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException