Uploaded image for project: 'Apache Cordova'
  1. Apache Cordova
  2. CB-2421

On Windows 8 , FileTransfer.upload returns wrong FileUploadResult

    XMLWordPrintableJSON

Details

    Description

      When reporting success, the existing code attempts to read the original file as a string and report it as a response (instead of the server's response).
      It also calls a non-existent constructor new FileUploadResult(basicProperties.size, code, fileContent).

      When the uploaded file is not textual (e.g. a JPEG image), the current code fails altogether because dataReader.readString throws an exception.

      Here is a possible correction:

      Old Code:
      storageFile.getBasicPropertiesAsync().done(function (basicProperties) {
      Windows.Storage.FileIO.readBufferAsync(storageFile).done(function (buffer)

      { var dataReader = Windows.Storage.Streams.DataReader.fromBuffer(buffer); var fileContent = dataReader.readString(buffer.length); dataReader.close(); win(new FileUploadResult(basicProperties.size, code, fileContent)); }

      );
      }, function () {
      error(FileTransferError.INVALID_URL_ERR);
      });

      Correction:
      storageFile.getBasicPropertiesAsync().done(function (basicProperties) {
      var res = new FileUploadResult();
      res.bytesSent=basicProperties.size;
      res.responseCode=response.status;
      res.response=response.responseText;
      win(res);
      });

      Possible a more elegant correction would be to add the missing constructor for FileUploadResult

      Attachments

        Activity

          People

            purplecabbage Jesse MacFadyen
            youval.bronicki@gmail.com Youval Bronicki
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: