Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
1.1.0
-
None
-
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
Description
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.
Attachments
Issue Links
- links to
Activity
Got the same error today -
06-23 12:04:46.661: E/PluginManager(32495): java.lang.IllegalStateException: Tried to perform an IO operation on the WebCore thread. Use CordovaInterface.getThreadPool() instead.
06-23 12:04:46.661: E/PluginManager(32495): at org.apache.cordova.CordovaResourceApi.assertBackgroundThread(CordovaResourceApi.java:400)
06-23 12:04:46.661: E/PluginManager(32495): at org.apache.cordova.CordovaResourceApi.mapUriToFile(CordovaResourceApi.java:149)
06-23 12:04:46.661: E/PluginManager(32495): at org.apache.cordova.file.ContentFilesystem.filesystemPathForURL(ContentFilesystem.java:202)
06-23 12:04:46.661: E/PluginManager(32495): at org.apache.cordova.file.FileUtils.remapUri(FileUtils.java:258)
06-23 12:04:46.661: E/PluginManager(32495): at org.apache.cordova.PluginManager.remapUri(PluginManager.java:473)
06-23 12:04:46.661: E/PluginManager(32495): at org.apache.cordova.CordovaResourceApi.remapUri(CordovaResourceApi.java:136)
06-23 12:04:46.661: E/PluginManager(32495): at org.apache.cordova.filetransfer.FileTransfer.upload(FileTransfer.java:310)
06-23 12:04:46.661: E/PluginManager(32495): at org.apache.cordova.filetransfer.FileTransfer.execute(FileTransfer.java:183)
06-23 12:04:46.661: E/PluginManager(32495): at org.apache.cordova.CordovaPlugin.execute(CordovaPlugin.java:98)
06-23 12:04:46.661: E/PluginManager(32495): at org.apache.cordova.PluginManager.exec(PluginManager.java:133)
06-23 12:04:46.661: E/PluginManager(32495): at org.apache.cordova.CordovaBridge.jsExec(CordovaBridge.java:59)
06-23 12:04:46.661: E/PluginManager(32495): at org.apache.cordova.engine.SystemExposedJsApi.exec(SystemExposedJsApi.java:41)
06-23 12:04:46.661: E/PluginManager(32495): at org.chromium.base.SystemMessageHandler.nativeDoRunLoopOnce(Native Method)
06-23 12:04:46.661: E/PluginManager(32495): at org.chromium.base.SystemMessageHandler.handleMessage(SystemMessageHandler.java:39)
06-23 12:04:46.661: E/PluginManager(32495): at android.os.Handler.dispatchMessage(Handler.java:102)
06-23 12:04:46.661: E/PluginManager(32495): at android.os.Looper.loop(Looper.java:148)
06-23 12:04:46.661: E/PluginManager(32495): at android.os.HandlerThread.run(HandlerThread.java:61)
I am using the latest Cordova and Android platform, installed today only.
rahulpandey, looking at the stack trace it I can see that you're using content:// uri to upload file, however i wasn't able to reproduce the problem. Could you please provide a code that reproduces the problem. Also please post cordova, cordova-android and file-transfer plugin versions you're using. You can get it via cordova --version && cordova platform ls && cordova plugin ls
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)
;
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 =
;
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)
, options, true);
}
var onSuccess = function(imgData) {
//uploadImage(imgData);
window.resolveLocalFileSystemURL(imgData, function(entry)
);
};
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
catch (Exception e)
{ e.printStackTrace(); } }
});
} else
return true;
Please wrap your code into {noformat} blocks, to make it readable. Also it's not very clear, what is the value of checkInImage - is that a cdvfile://localhost/content/... url? What kind of camera source should i use to reproduce - PHOTOLIBRARY or CAMERA?
Hi,
Sorry for the formatting, I have edited the code to remove that checkInImage variable and yes it it the cdvfile url image. You can use PhotoLibrary source. I mostly tried with that only.
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(commentImage, 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 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);
GitHub user vladimir-kotikov opened a pull request:
https://github.com/apache/cordova-plugin-file-transfer/pull/154
CB-9022 Resolve source URI on background thread in
<!--
Please make sure the checklist boxes are all checked before submitting the PR. The checklist
is intended as a quick reference, for complete details please see our Contributor Guidelines:
http://cordova.apache.org/contribute/contribute_guidelines.html
Thanks!
-->
-
-
- Platforms affected
Android
- Platforms affected
-
-
-
- What does this PR do?
This PR fixes application crash when trying to upload file from 'Content' file system, specified by `cdvfile://localhost/content/...` URI.
- What does this PR do?
-
-
-
- What testing has been done on this change?
Manual and automated testing
- What testing has been done on this change?
-
-
-
- Checklist
-
- [x] [ICLA](http://www.apache.org/licenses/icla.txt) has been signed and submitted to secretary@apache.org.
- [x] [Reported an issue](http://cordova.apache.org/contribute/issues.html) in the JIRA database
- [x] Commit message follows the format: "CB-3232: (android) Fix bug with resolving file paths", where CB-xxxx is the JIRA ID & "android" is the platform affected.
- [ ] Added automated test coverage as appropriate for this change.
We should call `remapUri` on background thread otherwise it throws `IllegalStateException` when trying to remap 'cdvfile://localhost/content/...' URIs via `ContentFilesystem`
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/vladimir-kotikov/cordova-plugin-file-transfer CB-9022
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/cordova-plugin-file-transfer/pull/154.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #154
commit 15551921f0304c4987d50d635aa2ea24a3a2c565
Author: Vladimir Kotikov <kotikov.vladimir@gmail.com>
Date: 2016-08-18T13:30:19Z
CB-9022 Resolve source URI on background thread in
We should call remapUri on background thread otherwise it
throws IllegalStateException when trying to remap 'cdvfile://localhost/content/...' URIs via ContentFilesystem
Thanks for details. Until the PR is merged you can workaround this in JS code by using `file://` or `content://` URIs rather than `cdvfile://`
Github user cordova-qa commented on the issue:
https://github.com/apache/cordova-plugin-file-transfer/pull/154
Cordova CI Build has completed successfully.
*Commit* - [Link](https://github.com/apache/cordova-plugin-file-transfer/pull/154/commits/3ccf9f8462c1de61c15c3841f77010b25fd6de58)
*Dashboard* - [Link](http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-file-transfer-pr/35/)
Commit 3ccf9f8462c1de61c15c3841f77010b25fd6de58 in cordova-plugin-file-transfer's branch refs/heads/master from vladimir.kotikov
[ https://git-wip-us.apache.org/repos/asf?p=cordova-plugin-file-transfer.git;h=3ccf9f8 ]
CB-9022 Resolve source URI on background thread
We should call remapUri on background thread otherwise it
throws IllegalStateException when trying to remap 'cdvfile://localhost/content/...' URIs via ContentFilesystem
Github user asfgit closed the pull request at:
https://github.com/apache/cordova-plugin-file-transfer/pull/154
Commit 2b6b6d9333848beb05a6128242701261467b5d69 in cordova-plugin-file-transfer's branch refs/heads/master from anemitoff
[ https://git-wip-us.apache.org/repos/asf?p=cordova-plugin-file-transfer.git;h=2b6b6d9 ]
CB-9022 Fix exception thrown by call to remapApi on main thread
When reamapApi was being called for device file it was performing IO on
the WebCore thread and throwing an IllegalState exception. This seems
to have only been a problem when local URL corresponded to a video file.
Moved calls to remapApi for device URLs within new thread context so
that IO is performed on background thread.
This is the same fix as 3ccf9f8 but for `download` operation
This closes #124
Yes, the bug seems to be on android kitkat version.