Fine Uploader error with internet explorer 10 - javascript

I am using Fine Uploader 3.7.0 in a project with Chrome and Firefox and it works fine, but with Internet Explorer 10 the files are uploaded correctly but the user always get the "Upload failed" error message, even with the demo tests:
<script>
$(document).ready(function() {
var errorHandler = function(event, id, fileName, reason) {
qq.log("id: " + id + ", fileName: " + fileName + ", reason: " + reason);
};
var myUploader = new qq.FineUploader({
element: $('#basicUploadButton')[0],
multiple: false,
callbacks: {
onError: errorHandler
},
request: {
endpoint: '/fineupload/receiver'
}
});
});
</script>
<div class="fineUploader">
<span>Please upload your files for automated process.</span>
<div id="basicUploadButton" class="upload-btn"></div>
</div>
<br />
<div>Close Window</div>
I debugged the servlet and I see that I am sending this:
writer.print("{\"success\": true, \"uuid\": \"" + requestParser.getUuid() + "\", \"originalFileName\": \"" + requestParser.getFilename() + "\"}");
so I think that the JSON I am supposed to get is correct.
Any ideas why can this be failing with IE10? I also tried with the compatibility modes and didn't work.
Updated: Console log:
[FineUploader 3.7.0] Error when attempting to parse xhr response text (SyntaxError: Invalid character)
id: blog.jpg, fileName: Upload failure reason unknown, reason: [object XMLHttpRequest]
Thanks!

The problem was due to the JSON response I was creating in Java.
Looking at the Network tab in IE10 developer tools (thanks Ray for the advice) I get:
{"error": "java.io.FileNotFoundException: C:\data\uploads\fd9b5240-5661-4f07-a216-7a76b2250b00_C:\folder\blog.jpg (The filename, directory name, or volume label syntax is incorrect)"}
I was using
writer.print("{\"success\": true, \"uuid\": \"" + requestParser.getUuid() + "\", \"originalFileName\": \"" + requestParser.getFilename() + "\"}");
Instead of that
JSONObject json = new org.json.JSONObject();
json.put("success", true);
json.put("uuid", requestParser.getUuid());
json.put("originalFileName", requestParser.getFilename());
writer.print(json.toString());
works fine with every browser.
Anyway, I needed to avoid the file name that IE10 manages (C:\folder\blog.jpg) so I had to use
json.put("originalFileName", getCorrectFileName(requestParser.getFilename()));
with getCorrectFilename(String s) removing the "C:\folder\" part.

The question of "my file is sent to the server but Fine Uploader reports a failure" is a common one. As the docs state, you MUST return valid JSON in the response to Fine Uploader's upload POST requests. Based on your comments, you were not returning valid JSON. To verify that you are returning valid JSON, you can use a tool such as JSON Lint. You can examine the response payload via your browser's developer tools, or set the debug option to true in your Fine Uploader options.
As #mfeltner stated, you should be using a JSON serialization tool server-side when constructing your response.

Related

Namespace change in Google Cast custom sender application

I have an issue with a custom sender/receiver application was written a while back.
We recently merged to the cloud and the sender application which is a simple web page was moved and changed its URL from what it used to be.
http: //sdpc.webpage.com to what it is now https: //webpage.com/sdpc.
Now it appears my messages are not being sent over to the receiver application.
I have the following code to send the message to the receiver:
var applicationID = 'F7000000';
var namespace = 'urn:x-cast:com.webpage.cast.sdpc';
var session= null;
var driverRequest;
function sendMessage(message) {
if (session != null) {
location.reload();
session.sendMessage(namespace, message, onSuccess.bind(this,
"Message sent: " + message), onError.bind(this, "Error: " + message));
// $('messageDiv').set('html', session.sendMessage(namespace, message, onSuccess.bind(this, "Message sent: " + message), onError));
} else {
chrome.cast.requestSession(function(e) {
session = e;
location.reload();
session.sendMessage(namespace, message, onSuccess.bind(this,
"Message sent: " + message), onError.bind(this, "Error: " + message));
// $('messageDiv').set('html', session.sendMessage(namespace, message, onSuccess.bind(this, "Message sent: " + message), onError));
}, onError);
}
}
this all worked before we moved the folder over to what is now it's new location on the cloud. I made sure to change the receiver URL in the developer google console to point to its new location, but no luck. Could the namespace be the issue? It's the only thing I'm not sure about.
I believe the sender to receiver connection isn't even being established because I have code setup for any errors while displaying the image to the chrome cast and I am not seeing anything.
I've looked on the google forums and GitHub but I can't think of anything else that might be causing this issue.
not really sure why this got flagged down without letting me know why.
However I managed to solve my own question in case anyone ever needs it. As it turns out my web page was internal so by changing the url on the developer's google web page the receiver was not able to be reached from the outside world. However as soon as I transferred the project + url to a public facing web page and it worked. It took a couple of hours before it registered but it worked.

How to handle authentication popup in Firefox with Selenium WebDriver using Java

I am trying to create extension for bypassing server authentication, install it on Firefox browser and pass the .xpi file while driver creation so that it gets invoked while login and the server authentication is bypassed.
Facing error while installing the .xpi file on firefox.
Error: "This add on could not be installed because it appears to be corrupt"
Steps
1. Created a manifest.json file (Code mentioned below)
{
“name”: “Webrequest API”,
“version”: “1.0”,
“description”: “Extension to handle Authentication window”,
“permissions”: [
“webRequest”,
“webRequestBlocking”,
“”
],
“background”: {
“scripts”: [“webrequest.js”]
},
“manifest_version”: 2
}
Created webrequest.js file. Code mentioned below.
var target = “https://sso.viacomcloud.com/”;
var myCredentials = {
username: “getestone”,
password: “V*******”
}
var pendingRequests = [];
// A request has completed.
// We can stop worrying about it.
function completed(requestDetails) {
console.log(“completed: ” + requestDetails.requestId);
var index = pendingRequests.indexOf(requestDetails.requestId);
if (index > -1) {
pendingRequests.splice(index, 1);
}
}
function provideCredentialsSync(requestDetails) {
// If we have seen this request before, then
// assume our credentials were bad, and give up.
if (pendingRequests.indexOf(requestDetails.requestId) != -1) {
console.log(“bad credentials for: ” + requestDetails.requestId);
return {cancel:true};
}
pendingRequests.push(requestDetails.requestId);
console.log(“providing credentials for: ” + requestDetails.requestId);
return {authCredentials: myCredentials};
}
browser.webRequest.onAuthRequired.addListener(
provideCredentialsSync,
{urls: [target]},
[“blocking”]
);
browser.webRequest.onCompleted.addListener(
completed,
{urls: [target]}
);
Created a zip file using 7-zip file manager and renamed the zip file as Ext.xpi
Opened about:config on firefox (verson 70) and changed xpiextensionsignrequired to ‘False’
Opened about:addons on firefox. Selected ‘install extension from a file’. Select the Ext.xpi created in step 4 above.
I get the following error: ” this add on could not be installed because it appears to be corrupt.” instead of getting the Install option on Firefox browser.
Please help
#SubjectiveReality
Try using the class "Robot" and send keys in case you are looking for a quick solution.
Robot rb= new Robot();
rb.Keypress().....

JxBrowser loading HTML from resource URL, cannot open websocket

I am using JxBrowser to load a html file that resides in a jar. This html file has a websocket that is failing to connect (I receive code 106 in the onclose event)
I am getting these errors from JxBrowser
09:20:18.381 INFO: 09:20:18 SEVERE: [1228/092018.371:ERROR:validation_errors.cc(87)] Invalid message: VALIDATION_ERROR_DESERIALIZATION_FAILED
09:20:18.382 INFO: 09:20:18 SEVERE: [1228/092018.371:ERROR:render_process_host_impl.cc(4145)] Terminating render process for bad Mojo message: Received bad user message: Validation failed for WebSocket::AddChannelRequest deserializer [VALIDATION_ERROR_DESERIALIZATION_FAILED]
09:20:18.382 INFO: 09:20:18 SEVERE: [1228/092018.371:ERROR:bad_message.cc(23)] Terminating renderer for bad IPC message, reason 123
Here is my code for creating the browser
Browser browser = new Browser();
BrowserView browserView = new BrowserView(browser);
browser.addConsoleListener(new ConsoleListener() {
#Override
public void onMessage(ConsoleEvent ce) {
System.out.println("Console log from " + ce.getSource() + " message " + ce.getMessage());
}
});
BrowserContext browserContext = browser.getContext();
ProtocolService protocolService = browserContext.getProtocolService();
protocolService.setProtocolHandler("jar", new ProtocolHandler() {
#Override
public URLResponse onRequest(URLRequest request) {
try {
URLResponse response = new URLResponse();
URL path = new URL(request.getURL());
InputStream inputStream = path.openStream();
DataInputStream stream = new DataInputStream(inputStream);
byte[] data = new byte[stream.available()];
stream.readFully(data);
response.setData(data);
String mimeType = getMimeType(path.toString());
response.getHeaders().setHeader("Content-Type", mimeType);
return response;
} catch (Exception ignored) {
}
return null;
}
});
URL url = getClass().getClassLoader().getResource("resources/example.html");
browser.loadURL(url.toExternalForm());
Here is a simplified version of my WebSocket code
this.ws = new WebSocket('ws://127.0.0.0:1337');
this.ws.onopen = () => {
console.log('OnOpen');
};
this.ws.onmessage = (evt) => {
console.log('OnMessage ' + evt.data);
};
this.ws.onerror = (event) => {
console.log('OnError');
};
this.ws.onclose = (event) => {
console.log('OnClose ' + event.code + ' ' + event.reason);
};
I am having a hard time finding information on the error messages received from Chromium. Could there be problems because the URL is using the jar: protocol? Or is this a problem because chrome does not allow unsecure websocket connections?
(Edit) The socket connects when I use the JxBrowser's loadHTML method and supply the string text of the HTML file. So I believe this has something to do with the fact that I am loading from a resource URL, and not to do with chrome not allowing unsecure websocket connections. I really dont want to have to stream the file contents so that I can use loadHTML.
(Edit2) Loading the HTML from a file URL also works. I guess I can create a local copy of the HTML file in the jar and load that instead. I am disappointed that I cannot do this using the jar URL, I guess it might be a limitation of JxBrowser.
From what you described, the issue is definitely related to the URL being using the jar: protocol. Seems like websocket works only with file: http: and https: protocols.
The best solution in this case will be to read HTML from the example.html file and then load it using the loadHTML method instead of the loadURL.
I have decided to copy the HTML files from the jar into a local folder, and using a File URL to load them.

Cordova App Creating a directory

I am building a Cordova App by myself and i need to create a new folder to store images in phone's internal storage. I have visited a lot of articles online and everyone is giving the same solution but it is not working for me.
Following is the code i am using in OnDeviceReady event but it is not working.
var new_directory = 'TEST';
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem) {
fileSystem.root.getDirectory(new_directory, { create: true }, function (file) {
alert("got the file: "+ file.name + ', ' + file.fullPath);
});
}, function(error) {
alert("can't even get the file system: " + error.code);
});
For Debugging i have also tried to alert
cordova.file
object but it is shown as undefined.
I have tried writing simple file request statement even its is not working
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, alert('success'), alert('failed'));
also the rest of the javascript code does not work when i write above code.
Please help me to get on with this.
Have you been asked to grant the proper permissions when you try to save the file? A window like this should have appeared:
If this is not the case, you are using an obsolete plugin version. Otherwise, there is something wrong with your code, sorry but I can't help you with that.

How to call browser function with URL/URI local to the client?

I want to call a browser function, e.g. AddSearchProvider(engineURL), which requires an URL to a XML-file. However, I want the user to generate the content of the XML-file himself, thus I want to call the function by passing (a reference to) the user generated content directly. It is key that all of this happens client-side only, such that no server is required to temporarily host files in the process.
I tried to encode the XML file into the URI:
uri = "data:application/xml;charset=utf-8," + encodeURIComponent($('#edit-search-engine').val());
window.external.AddSearchProvider(uri);
But Firefox (57.0) rejects this approach with the following message:
I guess¹ Firefox expects a "true", remote, URL. How can I realize the above functionality without a server in the loop?
¹Update: Firefox is indeed enforcing the URL to be of HTTP, HTTPS or FTP:
[...]
// Make sure the URLs are HTTP, HTTPS, or FTP.
let isWeb = ["https", "http", "ftp"];
if (isWeb.indexOf(engineURL.scheme) < 0)
throw "Unsupported search engine URL: " + engineURL;
if (iconURL && isWeb.indexOf(iconURL.scheme) < 0)
throw "Unsupported search icon URL: " + iconURL;
[...]

Categories