Objective-c Warning for the webview of a dropbox plugin - javascript

Warning recieved : WebKit discarded an uncaught exception in the webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame: delegate: The view passed in does not have a window.
dropbox plugin method for getting the files from dropbox inside it i have created an array to get the files and send it to javascript to display the output
getfiles:-
jscallback=[NSString stringWithFormat:#"getFilename(%#)",dropBoxArray];
[self writeJavascript:jscallback];
Method defined in javascript
window.getFilename=function(str)
{
alert(str);
cordova.exec(linkDropboxCB, linkDropboxFail,"DropboxPlugin","getfiles", [""]);
}
getfiles is the method in the dropbox plugin,which contains the above code.
Please help me to remove the warning.

Related

WordPress - ERR_BAD_RESPONSE admin-ajax-php file upload

I'm trying to upload files in WordPress using admin-ajax.php
I have this code in my functions.php file
function upload_docs(){
var_dump($_FILES);
}
add_action('wp_ajax_nopriv_upload_docs', 'upload_docs');
add_action('wp_ajax_upload_docs', 'upload_docs');
The function at the moment is a test that I want to use to debug what information is passed from the front-end which is a Vue app hosted in a page template.
I've correctly loaded and localized the Vue CSS and js files and after the build, in my localhost, I'm able to pass the other forms I have configured on my functions file
On the front-end side, the Vue app has this method that will add the needed information to the WordPress backend
sendUploadForm(){
let documents = this.$refs.uploadedFiles.files
let userData = new FormData()
for(let i = 0; i < documents.length; i++ ){
userData.append('file[]', documents[i])
}
userData.append('action', 'upload_docs')
axios.post(wp_param.ajaxurl, userData).then( res => {
console.log(res)
}).catch( e => console.log(e) )
}
What is going wrong with the code? I will always get a 500 error status code ERR_BAD_RESPONSE and I don't know if the function is called because I'm unable to see any var_dump or var_export from PHP. I've tried to enable the debug in wp-config file but nothing changed.
Any suggestion?
Add these additional two lines under your WP_DEBUG one, make the error happen again, and check in the folder wp-content/ if you see a new file debug.log.
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);
Consider:
Implementing nonces and permission checks to protect your endpoints
If only logged in users are supposed to be able to upload files, ensure the no_priv method is properly locked down
Using a custom REST API endpoint instead of admin-ajax https://developer.wordpress.org/rest-api/extending-the-rest-api/adding-custom-endpoints/
Terminate your function with wp_die(); when using AJAX in WordPress
I was stuck with this problem because of WordPress plugin conflicts.
You can disable unused plugins and check.

The setFilesToUpload action is not working for me

I'm trying to upload a file to the web application I'm testing. The only Html I can identify the upload with is the class which is 'file-input'.
Currently what I have done is this, in my page-model file I have:
this.importSection = Selector('.file-input');
And in my test file I have:
.setFilesToUpload(page.importSection, './my-file.xlsx')
I have also tried directly calling the element within my test file as below:
.setFilesToUpload('.file-input', './my-file.xlsx')
.setFilesToUpload(Selector('.file-input'), './my-file.xlsx')
When running either of these I am getting the following error:
"The specified selector does not match a file input element."
Any ideas what I am doing wrong, I've searched on the testcafe & not sure what to do next.
This works:
Within the page-model file I have:
this.importSection = Selector('input');
Then within my test file .setFilesToUpload(page.importSection.withAttribute('type', 'file'), './fileName')

Adobe Reader Javascript Open .DOC

I just tried to many code from internet to open automatically .doc which are attached in PDF but i get this : "Cannot open type of application/msword"
I tried this:
var oDoc = openDataObject("image.doc"); console.println(oDoc.path);
I tried to find another function which are specify the type of the document and to can open it in Microsoft Word!
Regards
The openDataObject method will throw an exception instead of returning a Doc if any of the following conditions are true:
The document that this method is being called for does not contain the requested embedded data object.
The data object is not a PDF document.
Permissions forbid opening attachments by means of JavaScript.
Instead of openDataObject which tells the viewer to open the file, use exportDataObject with the launch parameter. 0 will prompt the user to save the file, 1 will save the file and launch it.
this.exportDataObject({ cName: "image.doc", nLaunch: 1 });

Getting Uncaught ReferenceError: camera is not defined

I have JS camera object in codenameone project while I am trying to call that object from a js file its giving me the Uncaught ReferenceError: camera is not defined
error in my chrome browser, while i am trying to upload a image
Below is my codenameone code
camera.set("capture",new JSFunction(){
public void apply(JSObject self, Object[] args) {
Display.getInstance().openImageGallery(new ActionListener(){
#Override
public void actionPerformed(ActionEvent evt) {
String imagePath ="";
if(evt!=null){
imagePath=(String)evt.getSource();
final JSObject uploadedFile = (JSObject)ctx.get("document.getElementById('uploadedFile')");
uploadedFile.set("value",imagePath);
}
}
});
}
});
ctx.set("camera", camera);
Below is my js file where i am getting error for the camera object I used to give window.camera but at that its giving the same above error for capture where capture is the button id which i am using in my html file.
Below is my js file
document.getElementById('capture')
.addEventListener('click', function(){
camera.capture(function(){
var results = document.getElementById("uploadedFile").value;
document.getElementById("uploadedFile").value=results;
})
}, true);
JS camera file is not loaded thats why you are getting this error.
Make sure file is loaded above this code.
structure should be like this-->
file src included
then-->
your script here
I'm guessing you are trying to access HTML5 API's within an embedded browser component. It doesn't have access to all the bells and whistles of HTML5 and might fail. I'm not sure if these will work on the device either although you would have a better chance there than in the simulator.

Read local file in Phonegap

I'm trying to read a local file in Phonegap to load the language strings for the application and I can't make it work :(
The code is pretty straightforward:
var pathToLocalFile = "/home/user/android/assets/www/js/";
var langCache = new FileReader();
langCache.onload = function(data){
col = JSON.parse(data);
refreshAllStrings();
};
langCache.onerror = function(err){
debug.error(err);
};
langCache.readAsText(pathToLocalFile+currentLang+'.json');
This code doesn't work on the Ripple emulator and I replaced it with
var pathToLocalFile = "file:///android_asset/www/js/";
in case of android, with the same result:
Uncaught TypeError: Object #<Console> has no method 'warning' cordova-2.4.0.js:2616
initRead cordova-2.4.0.js:2616
FileReader.readAsText cordova-2.4.0.js:2660
loadLanguage
In the Ripple emulator, I started Chrome with google-chrome -–allow-file-access-from-files and the Android config and manifest has all the permissions for and the plugins set.
Of course I'm missing something, but any idea what this could be?
Regards.
If the file is under the www folder of your app you don't need to add '/home/..' or 'file:///'. You should just be able to load the contents using an "AJAX" fetch even though it is bundled in the app.
$.get('js/filename.ext');
The error you're seeing is actually a result of cordova-2.4.0.js calling a non-existent "warning" method. It should be console.warn. It is attempting to warn you that using a string for the readAsText method is now deprecated, and that you should use a File reference instead.
What should be happening is a console.warn of "Using a string argument with FileReader.readAs functions is deprecated."

Categories

Resources