title: Phonegap FileUpload Java Server
body: <p>I am trying to upload an Image on Java Server.the File is trnsfering from android device but saving null on server .</p>
  
  <p>Here is server code</p>
  
  <pre><code>public UploadMediaServerResponse uploadFileForFunBoard(@FormDataParam("photoPath") InputStream photoInputStream,
              @FormDataParam("photoPath") FormDataContentDisposition photoFileDetail,
              @FormDataParam("userId") int userId, @FormDataParam("mediaType") String mediaType,
              @FormDataParam("title") String title,@FormDataParam("funBoardId") int funBoardId)
      {
  
          MediaContenModel mediaContenModel = new MediaContenModel();
          mediaContenModel.setFunBoardId(funBoardId);
          mediaContenModel.setMediaType(mediaType);
          mediaContenModel.setUserId(userId);
  
          UploadMediaServerResponse uploadMediaServerResponse = new UploadMediaServerResponse();
          boolean isMediaProcessedAndUploaded = true;
          String mediaProcessingError = "";
  
          if (photoInputStream != null &amp;&amp; photoFileDetail != null)
          {
              uploadMediaServerResponse = mediaService.uploadOnServer(photoInputStream,
                      photoFileDetail.getFileName(), userId+"");
              if (uploadMediaServerResponse != null
                      &amp;&amp; !uploadMediaServerResponse.getMediaUrl().equalsIgnoreCase("ERROR"))
              {
                  mediaContenModel.setImageUrl(uploadMediaServerResponse.getMediaUrl());
                  logger.debug("ContentService --&gt; createStroyline --&gt; fearture Image url ::"
                          + uploadMediaServerResponse.getMediaUrl());
              }
              else
              {
                  isMediaProcessedAndUploaded = false;
                  mediaProcessingError = uploadMediaServerResponse.getMediaUrl();
                  logger.debug("ContentService --&gt; createStroyline --&gt;  mediaProcessingError ::"
                          + mediaProcessingError);
              }
          }
  
          if (isMediaProcessedAndUploaded)
          {
              UploadMediaServerResponse response = funBoardService.uploadMediaContent(mediaContenModel);
              uploadMediaServerResponse.setMediaUrl(response.getMediaUrl());
          }
          else
          {
              uploadMediaServerResponse.setError("Task Failed");
              uploadMediaServerResponse.setStatus(ServiceAPIStatus.FAILED.getStatus());
          }
          return uploadMediaServerResponse;
      }
  </code></pre>
  
  <p>here is my phonegap code </p>
  
  <pre><code>var pictureSource;   
  var destinationType; 
  
  
  function onPhotoURISuccess(imageURI) 
  {
      console.log(imageURI);
      var largeImage = document.getElementById('largeImage');
      largeImage.style.display = 'block';
      largeImage.src = imageURI;
  
  
  
  
  
  
  
  
  
  
   var options = new FileUploadOptions();
              options.fileKey="photoPath";
              options.fileName=imageURI.substr(imageURI.lastIndexOf('/')+1);
              options.mimeType="image/jpeg";
  
  
  
                  options.params = {
                              "userId": 1,
                              "funBoardId": 3,
                              "mediaType": 'image'
                          };            
  
  
              console.log(JSON.stringify(options));
  
              var ft = new FileTransfer();
              ft.upload(imageURI, _BaseURL+"mobile/userService/funboard/upload", win, fail, options);
  
  
  
  }
  
  function onPhotoDataSuccess(imageURI) 
  { 
      var imgProfile = document.getElementById('imgProfile');
      imgProfile.src = imageURI;
      if(sessionStorage.isprofileimage==1)
      {
          getLocation();
      }
      movePic(imageURI);
  }
  
  function onFail(message) 
  {
      alert('Failed because: ' + message);
  }
  
  function movePic(file)
  { 
      window.resolveLocalFileSystemURI(file, resolveOnSuccess, resOnError); 
  } 
  
  function resolveOnSuccess(entry)
  { 
      var d = new Date();
      var n = d.getTime();
      var newFileName = n + ".jpg";
      var myFolderApp = "MyAppFolder";
      window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSys) 
      {      
          fileSys.root.getDirectory( myFolderApp,
                  {create:true, exclusive: false},
                  function(directory) 
                  {
                      entry.moveTo(directory, newFileName,  successMove, resOnError);
                  },
          resOnError);
      },
      resOnError);
  }
  
  function successMove(entry) 
  {
      alert(entry.fullPath);
      sessionStorage.setItem('imagepath', entry.fullPath);
  }
  
  function resOnError(error) 
  {
      alert(error.code);
  }
  
  function capturePhotoEdit() 
  {
      navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 20, allowEdit: true,
      destinationType: destinationType.DATA_URL });
  }
  
  function getPhoto(source) 
  {
      navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 50, 
      destinationType: destinationType.FILE_URI,
      sourceType: source });
  }
  
  function onFail(message) 
  {
      alert('Failed because: ' + message);
   }
  
  
  
  function win(r) {
              console.log("Code = " + r.responseCode);
              console.log("Response = " + r.response);
              console.log("Sent = " + r.bytesSent);
              alert(r.response);
          }
  
          function fail(error) {
              alert("An error has occurred: Code = " = error.code);
          }
  </code></pre>
  
  <p>04-14 19:33:46.010: E/FileTransfer(13550): java.io.FileNotFoundException: http:///jeeyoh/mobile/userService/funboard/upload</p>
  
  <p>Thanks in Advance</p>