title: How to upload file to Laravel server from Android device using Retrofit correctly
body: <p>I'm trying to upload an image from Android Studio to Laravel server using Retrofit2 Multipart encoding, but i keep getting "500 Internal Server Error", which means something is going wrong server-side probably, but i can't pin what it is.</p>
  
  <p>this is my interface call (Android Studio):</p>
  
  <pre><code>@Multipart
  @POST("public/imagem")
  Call&lt;ResponseBody&gt; uploadImagem(@Part MultipartBody.Part part,
                                  @Part("name") RequestBody name,
                                  @Part("animal_id") long animal_id,
                                  @Part("ativo") int ativo);
  </code></pre>
  
  <p>this is the request (Android Studio):</p>
  
  <pre><code>    //Create a file object using file path
      File file = new File(filePath);
      // Create a request body with file and image media type
      RequestBody fileReqBody = RequestBody.create(MediaType.parse("image/*"), file);
      // Create MultipartBody.Part using file request-body,file name and part name
      MultipartBody.Part part = MultipartBody.Part.createFormData("upload", file.getName(), fileReqBody);
      //Create request body with text description and text media type
      RequestBody name = RequestBody.create(MediaType.parse("text/plain"), "image-type");
  
      WebService.getInstance().getService().uploadImagem(part, name, animal_id, 1).enqueue(new Callback&lt;ResponseBody&gt;() {
          @Override
          public void onResponse(Call&lt;ResponseBody&gt; call, Response&lt;ResponseBody&gt; response) {
              if (response.isSuccessful()) {
                  //THIS IS WHERE I WANT TO GET
              } else {
                  //THIS IS WHERE IM GETTING AT EVERYTIME
              }
          }
  
          @Override
          public void onFailure(Call&lt;ResponseBody&gt; call, Throwable t) {
  
          }
      });
  </code></pre>
  
  <p>this is my route (Laravel):</p>
  
  <pre><code>Route::post('imagem','ImagemController@createImagem');
  </code></pre>
  
  <p>this is the "createImagem" function inside "ImagemController" (Laravel):</p>
  
  <pre><code>public function createImagem(Request $request){
  
  $destinationPath = url('/midia'); //i have a "midia" folder inside "public" folder
  $image = $request-&gt;file('part');
  $name = $request-&gt;input('name');
  $image-&gt;move($destinationPath, $name);
  
  $dbPath = $destinationPath. '/'.$name;
  $imagem = new Imagem();
  $imagem-&gt;animal_id = $request-&gt;input('animal_id');
  $imagem-&gt;img_url = $dbPath;
  $imagem-&gt;ativo = $request-&gt;input('ativo');   
  $imagem-&gt;save();
  
  return response()-&gt;json($imagem);
  }
  </code></pre>
  
  <p>and these are the attributes inside "Imagem" table and their types:
  <a href="https://i.stack.imgur.com/vgYrP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vgYrP.png" alt=""></a></p>
  
  <p>but i'm getting 500 Internal Server Error, so probably something server-side isn't according to what would be right logically, can you help me find what is wrong in my code?</p>
  
  <p>ps. I do have other requests to this server that are fully functional, but all of them are just fields, while this has a file, which needs Multipart encoding, unlike the others.</p>
  
  <p>EDIT:
  This is the server error log:</p>
  
  <pre><code>[2019-06-11 21:21:03] local.ERROR: Call to a member function move() on null {"exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalThrowableError(code: 0): Call to a member function move() on null at /.../Controllers/ImagemController.php:28)
  </code></pre>
  
  <p>So it seems i am unable to get file with</p>
  
  <pre><code>$image = $request-&gt;file('part');
  </code></pre>