You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cordova.apache.org by "Rahul Pandey (JIRA)" <ji...@apache.org> on 2016/08/18 10:38:22 UTC

[jira] [Comment Edited] (CB-9022) Cordova Android Filetransfer returning null -"java.lang.IllegalStateException" - "CordovaInterface.getThreadPool()"

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

Rahul Pandey edited comment on CB-9022 at 8/18/16 10:37 AM:
------------------------------------------------------------


[~vladimir.kotikov] Here you go - 
Cordova Platform version -  android 5.1.1

File Transfer Plugin Version - cordova-plugin-file-transfer 1.5.1

File Plugin Version - cordova-plugin-file 4.2.0


 function uploadImage(commentImage) {
     var imageUploaded = function(data) {
         console.log("Image Uploaded ", data);
     };

     var ft = new FileTransfer();
     var options = new FileUploadOptions();
     var serverURL = connectUrl + "post/comment";
     options.fileKey = "file";
     if (commentImage.indexOf('jpg') != -1)
         options.fileName = "commentImage.jpg";
     else
         options.fileName = "commentImage.png";
     options.mimeType = "image/jpeg";
     options.chunkedMode = false;
     options.httpMethod = 'POST';
     var headers = { "boundary": "myuploadboundary" };
     options.headers = headers;
     var params = {};
     params.access_token = "Access token"
     params.postid = 1;
     params.comment = "This is my comment";
     options.params = params;
     ft.upload(checkInImage, encodeURI(serverURL), imageUploaded, function(e) {
         console.log(JSON.stringify(e));
     }, options, true);
 }



 var onSuccess = function(imgData) {

     //uploadImage(imgData);
     window.resolveLocalFileSystemURL(imgData, function(entry) {
         uploadImage(entry.nativeURL);
         //var filename = checkInImage.substr(commentImage.lastIndexOf('/') + 1);
     });
 };

 var onFail = function(error) {
     console.log(error);
 };

 var picSourceType = Camera.PictureSourceType.PHOTOLIBRARY;

 if (source === 'camera') picSourceType = Camera.PictureSourceType.CAMERA;

 var cameraOptions = {
     quality: 50,
     destinationType: Camera.DestinationType.FILE_URI,
     sourceType: picSourceType,
     allowEdit: false,
     targetWidth: 800,
     targetHeight: 800,
     saveToPhotoAlbum: true,
     encodingType: 0
 };
 navigator.camera.getPicture(onSuccess, onFail, cameraOptions);




For Temporary workaround I modified the line number 179 with these (inside boolean execute function) - 

    final String source = args.getString(0);
            final String target = args.getString(1);
            final JSONArray finalArgs = args;
            if (action.equals("upload")) {
                cordova.getThreadPool().execute(new Runnable(){
                  public void run() {
                    try {
                      upload(source, target, finalArgs, callbackContext);
                    } catch (Exception e) {
                      e.printStackTrace();
                    }
                  }
                });
            } else {
                download(source, target, args, callbackContext);
            }
            return true;





was (Author: rahulpandey):
Cordova Platform version -  android 5.1.1

File Transfer Plugin Version - cordova-plugin-file-transfer 1.5.1

File Plugin Version - cordova-plugin-file 4.2.0


 function uploadImage(commentImage) {
     var imageUploaded = function(data) {
         console.log("Image Uploaded ", data);
     };

     var ft = new FileTransfer();
     var options = new FileUploadOptions();
     var serverURL = connectUrl + "post/comment";
     options.fileKey = "file";
     if (commentImage.indexOf('jpg') != -1)
         options.fileName = "commentImage.jpg";
     else
         options.fileName = "commentImage.png";
     options.mimeType = "image/jpeg";
     options.chunkedMode = false;
     options.httpMethod = 'POST';
     var headers = { "boundary": "myuploadboundary" };
     options.headers = headers;
     var params = {};
     params.access_token = "Access token"
     params.postid = 1;
     params.comment = "This is my comment";
     options.params = params;
     ft.upload(checkInImage, encodeURI(serverURL), imageUploaded, function(e) {
         console.log(JSON.stringify(e));
     }, options, true);
 }



 var onSuccess = function(imgData) {

     //uploadImage(imgData);
     window.resolveLocalFileSystemURL(imgData, function(entry) {
         uploadImage(entry.nativeURL);
         //var filename = checkInImage.substr(commentImage.lastIndexOf('/') + 1);
     });
 };

 var onFail = function(error) {
     console.log(error);
 };

 var picSourceType = Camera.PictureSourceType.PHOTOLIBRARY;

 if (source === 'camera') picSourceType = Camera.PictureSourceType.CAMERA;

 var cameraOptions = {
     quality: 50,
     destinationType: Camera.DestinationType.FILE_URI,
     sourceType: picSourceType,
     allowEdit: false,
     targetWidth: 800,
     targetHeight: 800,
     saveToPhotoAlbum: true,
     encodingType: 0
 };
 navigator.camera.getPicture(onSuccess, onFail, cameraOptions);




For Temporary workaround I modified the line number 179 with these (inside boolean execute function) - 

    final String source = args.getString(0);
            final String target = args.getString(1);
            final JSONArray finalArgs = args;
            if (action.equals("upload")) {
                cordova.getThreadPool().execute(new Runnable(){
                  public void run() {
                    try {
                      upload(source, target, finalArgs, callbackContext);
                    } catch (Exception e) {
                      e.printStackTrace();
                    }
                  }
                });
            } else {
                download(source, target, args, callbackContext);
            }
            return true;




> Cordova Android Filetransfer returning null -"java.lang.IllegalStateException" - "CordovaInterface.getThreadPool()"
> -------------------------------------------------------------------------------------------------------------------
>
>                 Key: CB-9022
>                 URL: https://issues.apache.org/jira/browse/CB-9022
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: Plugin File Transfer
>    Affects Versions: 1.1.0
>         Environment: OS: Mac OS X Yosemite
> Node Version: v0.12.0
> Cordova CLI: 5.0.0
> Xcode version: Xcode 6.3.1 Build version 6D1002 
> ios-sim version: 3.1.1 
> ios-deploy version: 1.4.0 
> android 4.0.0-dev
>            Reporter: Mike Mullins
>            Assignee: Vladimir Kotikov
>              Labels: android, cannot-reproduce, wfc
>
> http://stackoverflow.com/questions/30201674/cordova-android-filetransfer-returning-null
> Attempting to do an android FileTransfer, plugin is working on iOS, i can't seem to get this to go!
> ADB lgocat output:
> E/PluginManager(23753): Uncaught exception from plugin
> E/PluginManager(23753): java.lang.IllegalStateException: Tried to perform an IO operation on the WebCore thread. Use CordovaInterface.getThreadPool() instead.
> FileTransferError
> body: null
> code: null
> exception: null
> http_status: null
> source: null
> target: null
> Trying a file transfer and coming back empty.... 
> Your system information:
> OS: Mac OS X Yosemite
> Node Version: v0.12.0
> Cordova CLI: 5.0.0
> Ionic CLI Version: 1.3.22
> Xcode version: Xcode 6.3.1 Build version 6D1002 
> ios-sim version: 3.1.1 
> ios-deploy version: 1.4.0
> ngCordova upload: http://ngcordova.com/docs/plugins/fileTransfer/
> Running in Crosswalk, not sure that makes any difference.



--
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