我正在使用Worklight 6.2,我正在尝试使用Android 4.0.3在Android设备上从相机上传图像,但每当我运行此代码时,它都无法完成上传。
以下是代码:
function sendReportImage(reportID){
WL.Logger.debug("Submitting report image: " + imageURI);
var options = new FileUploadOptions();
options.fileKey="file";
options.fileName=imageURI.substr(imageURI.lastIndexOf('/')+1);
options.mimeType="image/jpeg";
options.chunkedMode=false;
WL.Logger.debug("options" + options);
var ft = new FileTransfer();
ft.upload(imageURI, encodeURI(host + "/reports/"+reportID+"/contents"), imageUploadSuccess, imageUploadFail, options);
但它甚至没有进入FileTransfer行,它在FileUploadOptions上停止,显示此日志:
07-21 19:34:43.835: D/CordovaLog(6185): file:///data/data/com.my_program/files/www/default/worklight/cordova.js: Line 1036 : processMessage failed: Message: S01 StoragePlugin137844502 n1
07-21 19:34:43.835: I/Web Console(6185): processMessage failed: Message: S01 StoragePlugin137844502 n1 at file:///data/data/com.my_program/files/www/default/worklight/cordova.js:1036
07-21 19:34:43.867: D/CordovaLog(6185): file:///data/data/com.my_program/files/www/default/worklight/cordova.js: Line 1037 : processMessage failed: Error: ReferenceError: FileUploadOptions is not defined
07-21 19:34:43.867: I/Web Console(6185): processMessage failed: Error: ReferenceError: FileUploadOptions is not defined at file:///data/data/com.my_program/files/www/default/worklight/cordova.js:1037
07-21 19:34:43.898: D/dalvikvm(6185): GC_CONCURRENT freed 147K, 48% free 7679K/14535K, paused 2ms+3ms
07-21 19:34:43.898: D/CordovaLog(6185): file:///data/data/com.my_program/files/www/default/worklight/cordova.js: Line 1038 : processMessage failed: Stack: ReferenceError: FileUploadOptions is not defined
07-21 19:34:43.898: D/CordovaLog(6185): at sendReportImage (file:///data/data/com.my_program/files/www/default/js/report.js:206:2)
07-21 19:34:43.898: D/CordovaLog(6185): at Object.<anonymous> (file:///data/data/com.my_program/files/www/default/js/report.js:181:5)
07-21 19:34:43.898: D/CordovaLog(6185): at Object.<anonymous> (file:///data/data/com.my_program/files/www/default/worklight/wljq.js:1202:33)
07-21 19:34:43.898: D/CordovaLog(6185): at file:///data/data/com.my_program/files/www/default/worklight/wljq.js:1047:30
07-21 19:34:43.898: D/CordovaLog(6185): at Object.resolveWith (file:///data/data/com.my_program/files/www/default/worklight/wljq.js:1158:7)
07-21 19:34:43.898: D/CordovaLog(6185): at Object.resolve (file:///data/data/com.my_program/files/www/default/worklight/wljq.js:1247:33)
07-21 19:34:43.898: D/CordovaLog(6185): at Object.<anonymous> (file:///data/data/com.my_program/files/www/default/worklight/jsonstore.js:4007:28)
07-21 19:34:43.898: D/CordovaLog(6185): at Object.<anonymous> (file:///data/data/com.my_program/files/www/default/worklight/wljq.js:1202:33)
07-21 19:34:43.898: D/CordovaLog(6185): at file:///data/data/com.my_program/files/www/default/worklight/wljq.js:1047:30
07-21 19:34:43.898: D/CordovaLog(6185): at Object.resolveWith (file:///data/data/com.my_program/files/www/default/worklight/wljq.js:1158:7)
07-21 19:34:43.898: I/Web Console(6185): processMessage failed: Stack: ReferenceError: FileUploadOptions is not defined
07-21 19:34:43.898: I/Web Console(6185): at sendReportImage (file:///data/data/com.my_program/files/www/default/js/report.js:206:2)
07-21 19:34:43.898: I/Web Console(6185): at Object.<anonymous> (file:///data/data/com.my_program/files/www/default/js/report.js:181:5)
07-21 19:34:43.898: I/Web Console(6185): at Object.<anonymous> (file:///data/data/com.my_program/files/www/default/worklight/wljq.js:1202:33)
07-21 19:34:43.898: I/Web Console(6185): at file:///data/data/com.my_program/files/www/default/worklight/wljq.js:1047:30
07-21 19:34:43.898: I/Web Console(6185): at Object.resolveWith (file:///data/data/com.my_program/files/www/default/worklight/wljq.js:1158:7)
07-21 19:34:43.898: I/Web Console(6185): at Object.resolve (file:///data/data/com.my_program/files/www/default/worklight/wljq.js:1247:33)
07-21 19:34:43.898: I/Web Console(6185): at Object.<anonymous> (file:///data/data/com.my_program/files/www/default/worklight/jsonstore.js:4007:28)
07-21 19:34:43.898: I/Web Console(6185): at Object.<anonymous> (file:///data/data/com.my_program/files/www/default/worklight/wljq.js:1202:33)
07-21 19:34:43.898: I/Web Console(6185): at file:///data/data/com.my_program/files/www/default/worklight/wljq.js:1047:30
07-21 19:34:43.898: I/Web Console(6185): at Object.resolveWith (file:///data/data/com.my_program/files/www/default/worklight/wljq.js:1158:7) at file:///data/data/com.my_program/files/www/default/worklight/cordova.js:1038
任何暗示如何修复它?
答案 0 :(得分:0)
请尝试以下操作:在生成的Android项目中,在assets \ www \ default \ worklight \ cordova_plugins.js下,找到并替换:
- "file": "plugins/org.apache.cordova.file/www/FileUploadOptions.js",
+ "file": "plugins/org.apache.cordova.file/www/fileuploadoptions.js",
Additionaly,
请参阅此问题和答案:IBM Worklight 6.2 - error on StoragePlugin
存储插件声明存在已知缺陷,这可能是此处的根本原因。 作为解决方法,您需要打开config.xml并按如下所示进行更改:
- com.worklight.androidgap.plugin.storage.StoragePlugin
+ com.worklight.androidgap.plugin.StoragePlugin
请告知我们上述(以及可能两者都需要)是否以及哪些内容可以帮助您 如果您是IBM客户或业务合作伙伴,则需要打开PMR以接收包含此问题修复程序的iFix。
答案 1 :(得分:0)
现在它正在工作,这就是我必须做的事情:
找到文件&#34; assets / www / default / plugins / org.apache.cordova.file / www / FileUploadOptions.js&#34;在生成的Android项目上打开它。 在&#34; FileUploadOptions.js&#34;的顶部文件&#39;代码是这样的:
cordova.define("org.apache.cordova.file.FileUploadOptions1", function(require, exports, module) {
更改为此代码,如下所示:
cordova.define("org.apache.cordova.file.FileUploadOptions", function(require, exports, module) {
保存文件并选择&#34;运行方式&gt; Android应用程序&#34;。现在没有错误。