cordova-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (CB-9600) FileUploadOptions params not posted on iOS
Date Wed, 13 Apr 2016 09:31:25 GMT

    [ https://issues.apache.org/jira/browse/CB-9600?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15238948#comment-15238948
] 

ASF GitHub Bot commented on CB-9600:
------------------------------------

Github user mirko77 commented on the pull request:

    https://github.com/apache/cordova-plugin-file-transfer/pull/121#issuecomment-209334303
  
    I am posting to a Linux server (Ubuntu 14.10), PHP 5.6 backend , from an Ionic1.2.4 app.
    
    Here is the code, I removed the stuff not related to the bug
    
    ```
    
    var uploader = new FileTransfer();
    var options = new FileUploadOptions();
    var upload_URL = $rootScope.serverUrl + PARAMETERS.API_PATH + '/upload/' + slug;
    var file = $rootScope.file;
    var file_URI;
    
    function _onSuccess(r) {}
    
    function _onError(error) {}
    
    // Set options for multipart entity file
    options.fileKey = 'name';
    options.fileName = file.file_name;
    options.params = {
      data: {
        entry_uuid: "3e6450ee-eb6e-5387-0ec7-da7d13c6df30",
        id: "3e6450ee-eb6e-5387-0ec7-da7d13c6df30",
        attributes: {
          form: {
            type: "hierarchy",
            ref: "b8906ef28f944a26a1b7839290a5c2a6_57078c27d0238"
          }
        },
        type: "file",
        relationships: {
          branch: {
    
          },
          parent: {
    
          }
        },
        file: {
          input_ref: "b8906ef28f944a26a1b7839290a5c2a6_57078c27d0238_57078cbf32c50",
          type: "photo",
          name: "3e6450ee-eb6e-5387-0ec7-da7d13c6df30_1460537677.jpg"
        }
      }
    };
    
    if (auth) {
      options.headers = {
        Authorization: 'Bearer ' + auth;
      };
    }
    
    file_URI = file.file_path + file.project_ref + '/' + file.file_name;
    
    //append protocol for file on ios
    if (window.device.platform === PARAMETERS.IOS) {
      file_URI = 'file://' + file_URI;
      options.chunkedMode = false;
    }
    
    uploader.upload(file_URI, upload_URL, _onSuccess, _onError, options);
    ```
    
    content of the POST array of an Android request:
    
    `Array([data] => {
      "entry_uuid": "3e6450ee-eb6e-5387-0ec7-da7d13c6df30",
      "id": "3e6450ee-eb6e-5387-0ec7-da7d13c6df30",
      "attributes": {
        "form": {
          "type": "hierarchy",
          "ref": "b8906ef28f944a26a1b7839290a5c2a6_57078c27d0238"
        }
      },
      "type": "file",
      "relationships": {
        "branch": {},
        "parent": {}
      },
      "file": {
        "input_ref": "b8906ef28f944a26a1b7839290a5c2a6_57078c27d0238_57078cbf32c50",
        "type": "photo",
        "name": "3e6450ee-eb6e-5387-0ec7-da7d13c6df30_1460537677.jpg"
      }
    })`
    
    content of the POST array of an iOS request:
    
    `Array
    ()
    `
    
    



> FileUploadOptions params not posted on iOS
> ------------------------------------------
>
>                 Key: CB-9600
>                 URL: https://issues.apache.org/jira/browse/CB-9600
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: Plugin File Transfer
>    Affects Versions: 3.5.0, 3.7.0
>         Environment: iPhone - iOS 8.4.1
>            Reporter: TipsTrade
>            Assignee: jcesarmobile
>
> Using an app built using build.phonegap.com I'm finding that the FileUploadOptions.params
values aren't being posted - iOS (8.4.1) only posts the file multipart data. This isn't a
server side error as I've watched the POST using tcpdump/Wireshark and netcat.
> * PhoneGap v.3.7.0
> * Ionic Framework v.1.0.1
> * AngularJS v.1.3.13
> This is the code that is used to upload a test file. It generates a temporary file and
attempts to upload it.
> {code:javascript}
> $scope.doUploadTest = function() {
>     var q = $q.defer();
>     var promise = q.promise;
>     var text = "Test file content: " + new Date();
>     $window.requestFileSystem(LocalFileSystem.TEMPORARY, text.length, function(fs) {
>       q.resolve(fs);
>     }, function(err) {
>       q.reject(err);
>     });
>     promise
>     .then(function(fs) {
>       var qFile = $q.defer();
>       fs.root.getFile("upload.tmp", {create: true, exclusive: false}, function(entry)
{
>         qFile.resolve(entry);
>       }, function(err) {
>         qFile.reject(err);
>       });
>       return qFile.promise;
>     })
>     .then(function(entry) {
>       console.log("got file: " + entry.nativeURL);
>       var qWriter = $q.defer();
>       entry.createWriter(function(writer) {
>         qWriter.resolve({writer: writer, entry: entry});
>       }, function(err) {
>         qWriter.reject(err);
>       });
>       return qWriter.promise;
>     })
>     .then(function(response) {
>       var qWrite = $q.defer();
>       response.writer.onwriteend = function(evt) {
>         qWrite.resolve(response.entry);
>       };
>       response.writer.write(text);
>       return qWrite.promise;
>     })
>     .then(function(entry) {
>       $scope.error = entry;
>       var qUpload = $q.defer();
>       var options = new FileUploadOptions();
>       options.params = {
>         Value: {
>           list: [1, 2, 3],
>           text: "foo bar baz",
>           number: 1234
>         }
>       };
>       options.fileKey = "thefile";
>       options.fileName = entry.name;
>       options.mimeType = "text/plain";
>       options.chunkedMode = false;
>       options.headers = {
>         "X-Upload": (new Date()).toString()
>       };
>       var ft = new FileTransfer();
>       ft.upload(entry.nativeURL, "http://192.168.0.30:9100/", function(success) {
>         entry.remove();
>         qUpload.resolve(success);
>       }, function(err) {
>         entry.remove();
>         qUpload.reject(err);
>       }, options);
>       // Abort after 3 seconds
>       $timeout(function() {
>         console.log("Aborting upload - timed out");
>         ft.abort();
>       }, 3000);
>       return qUpload.promise;
>     })
>     .then(function(response) {
>       console.log("Upload succeeded");
>       $scope.error = response;
>     })
>     .catch(function(err) {
>       console.log("Upload failed");
>       $scope.error = err;
>     });
>     ;
>   };
> {code}
> The request made by an iPhone 6 (iOS v.8.4.1) is as follows:
> {noformat}
>     POST / HTTP/1.1
>     Host: 192.168.0.30:9100
>     Content-Type: multipart/form-data; boundary=+++++org.apache.cordova.formBoundary
>     Accept-Encoding: gzip, deflate
>     X-Upload: Tue Sep 01 2015 12:12:49 GMT+0100 (BST)
>     Connection: keep-alive
>     Accept: */*
>     User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 8_4_1 like Mac OS X) AppleWebKit/600.1.4
(KHTML, like Gecko) Mobile/12H321 (5348809648)
>     Content-Length: 261
>     Accept-Language: en-us
>     X-Requested-With: XMLHttpRequest
>     --+++++org.apache.cordova.formBoundary
>     Content-Disposition: form-data; name="thefile"; filename="upload.tmp"
>     Content-Type: text/plain
>     Content-Length: 58
>     Test file content: Tue Sep 01 2015 12:12:49 GMT+0100 (BST)
>     --+++++org.apache.cordova.formBoundary--
> {noformat}
> On a Motorola Moto X (2nd gen, Android 5.1) the request is this:
> {noformat}
>     POST / HTTP/1.1
>     Content-Type: multipart/form-data; boundary=+++++
>     X-Upload: Tue Sep 01 2015 12:52:24 GMT+0100 (BST)
>     User-Agent: Dalvik/2.1.0 (Linux; U; Android 5.1; XT1092 Build/LPE23.32-25.1)
>     Host: 192.168.0.30:9100
>     Connection: Keep-Alive
>     Accept-Encoding: gzip
>     Content-Length: 289
>     --+++++
>     Content-Disposition: form-data; name="Value"
>     {"list":[1,2,3],"text":"foo bar baz","number":1234}
>     --+++++
>     Content-Disposition: form-data; name="thefile"; filename="upload.tmp"
>     Content-Type: text/plain
>     Test file content: Tue Sep 01 2015 12:52:23 GMT+0100 (BST)
>     --+++++--
> {noformat}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org


Mime
View raw message