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-11118) Array and object params on upload ignored in ios
Date Tue, 21 Nov 2017 22:35:01 GMT

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

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

maverickmishra closed pull request #143: CB-11118: Add support for Array and Object params
in iOS
URL: https://github.com/apache/cordova-plugin-file-transfer/pull/143
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/src/ios/CDVFileTransfer.m b/src/ios/CDVFileTransfer.m
index 4775a6d..a245a69 100644
--- a/src/ios/CDVFileTransfer.m
+++ b/src/ios/CDVFileTransfer.m
@@ -25,6 +25,7 @@ Licensed to the Apache Software Foundation (ASF) under one
 #import <AssetsLibrary/ALAssetRepresentation.h>
 #import <AssetsLibrary/ALAssetsLibrary.h>
 #import <CFNetwork/CFNetwork.h>
+#import <Foundation/NSJSONSerialization.h>
 
 #ifndef DLog
 #ifdef DEBUG
@@ -203,6 +204,11 @@ - (NSURLRequest*)requestForUploadCommand:(CDVInvokedUrlCommand*)command
fileData
         if ([val respondsToSelector:@selector(stringValue)]) {
             val = [val stringValue];
         }
+        // if it is a valid json object get the NSString representation
+        if ([NSJSONSerialization isValidJSONObject:val]){
+            NSData *jsonData = [NSJSONSerialization dataWithJSONObject:val options:NSJSONWritingPrettyPrinted
error:nil];
+            val = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
+        }
         // finally, check whether it is a NSString (for dataUsingEncoding selector below)
         if (![val isKindOfClass:[NSString class]]) {
             continue;


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


> Array and object params on upload ignored in ios
> ------------------------------------------------
>
>                 Key: CB-11118
>                 URL: https://issues.apache.org/jira/browse/CB-11118
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: cordova-plugin-file-transfer
>    Affects Versions: 1.5.0
>         Environment: iOS
>            Reporter: Andrew Gaun
>              Labels: easyfix, iOS, triaged
>
> On iOS, CDVFileTransfer.m the method requestForUploadCommand will only allow params objects
with selector stringValue and NSString to be included with the request. 
> On Android objects and arrays are turned into strings when used as params
> Example:
> {code:javascript}
>   var fileUploadOptions = new FileUploadOptions();
>   fileUploadOptions.params = {
>     "array": [1,2,3],
>     "object": { 
>       "a": 1
>     },
>     number: 123
>   }
> {code}
> will return from iOS
> {code:javascript}
>   {
>     number: '123'
>   }
> {code}
> and from android
> {code:javascript}
>   {
>     array: '[1,2,3]',
>     object: '{"a":1}',
>     number: '123'
>   }
> {code}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

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


Mime
View raw message