How can I react to a finished upload with <h:inputFile>? - file-upload

I'm using Richfaces-4.3.5 on Wildfly-8.0.0.CR1 here, migrating from <rich:fileUpload> which doesn't work with JSF-2.2/Servlet-3.0. I'm replacing it with this snippet:
<rich:popupPanel id="testPop" autosized="true">
<h:form id="uploadF" enctype="multipart/form-data">
<h:inputFile value="#{bean.file}">
<a4j:ajax listener="#{bean.storeFile()}" render="#form,:fileListTbl"
oncomplete="#{rich:component('testPop')}.hide();" />
</h:inputFile>
</h:form>
</rich:popupPanel>
This works fine in that the storeFile method is called and I can access bean.file just fine. However, I'd like to close the rich:popupPanel when I'm done uploading, so I need to react to the success/complete events of the ajax request. But that doesn't seem possible - the popup stays visible and the response is clearly incomplete (indented for better readability):
<?xml version='1.0' encoding='UTF-8'?>
<partial-response id="j_id1">
<changes>
<update id="j_id1:javax.faces.ViewState:0">
<[CDATA[-1186354868983349335:-5499969782208038164]]>
</update>
<extension id="org.richfaces.extension"><render>#component</render></extension>
</changes>
</partial-response>
Though the richfaces debug messages indicate the handlers are being called:
RichFaces: Received 'success' event from <input id=uploadF:j_idt1136 ...>
RichFaces: Received 'complete' event from <input id=uploadF:j_idt1136 ...>
So, simple question: how can I get the popup to close and the components to be re-rendered?

i'm not sure if the problem is directly related to a4j:ajax or what's needed to be done to make it work with a4j:ajax, but the code below seems to work with f:ajax.
<h:form id="formId">
<h:commandLink value="popup"
onclick="#{rich:component('testPop')}.show(); return false;" />
</h:form>
<rich:popupPanel id="testPop" autosized="true">
<h:form id="uploadF" enctype="multipart/form-data">
<h:inputFile value="#{bean.file}">
<f:ajax listener="#{bean.storeFile()}" render="#form :fileListTbl"
onevent="eventHandler"/>
</h:inputFile>
</h:form>
</rich:popupPanel>
<script>
function eventHandler(event)
{
if (event.status == 'success')
{
#{rich:component('testPop')}.hide();
}
}
</script>

Related

Is there an easy way to make the fileupload work with IE11 without updating zk

In IE11 file upload button of ZK is not working.
I got few replies, It says after updating ZK it will fix the problem.
But we can't update ZK, So in this scenario is there any way to work out this problem any how.
If you can't upgrade ZK then you can try to "downgrade" the IE using "X-UA-Compatible" either as meta-tag or as a response header
here an example using the meta tag:
<?meta http-equiv="X-UA-Compatible" content="IE=10" ?>
<zk>
<fileupload label="upload" onUpload="alert(event.getMedia().getName())"/>
</zk>
and what it looks like in the browser (in the IE dev tools F12 you can check if the meta tag had an effect, you'll see that IE falls back to version 10):
http://screencast.com/t/ftheLA9Ud8
Finally I got the Solution.
AS IE 11 having problem to attach event for listening to open File chooser.
You just manually add the listener.
<button id="browsebtn" upload="true,maxsize=-1" visible="true" sclass="text">
<attribute w:name="doMouseDown_">
function (evt) {
}
</attribute>
</button>
Its simple and weird, However what I found is make the parent component as draggable="true"
<row draggable="true">
<div style="text-align : right;">
<label value="Image File:" />
</div>
<fileupload id="fileUpload" label="Upload" tooltiptext="Click to upload image file."/>
</row>
Now suddenly you will see your fileupload button in ZK started working correctly for IE11 as well.

Google script HTML api can´t process file upload field

I am trying to create a simple web app in google scripts with the HTML api.
code.gs
function doGet() {
return HtmlService.createHtmlOutputFromFile('index');
}
function processForm(formObject) {
var formBlob = formObject.myFile;
var driveFile = DriveApp.createFile(formBlob);
return driveFile.getUrl();
}
index.html
<script>
function updateUrl(url) {
var div = document.getElementById('output');
div.innerHTML = 'Got it!';
}
</script>
<form id="myForm">
<input name="myFile" type="file" />
<input type="button" value="Submit"
onclick="google.script.run
.withSuccessHandler(updateUrl)
.processForm(this.parentNode)" />
</form>
<div id="output"></div>
The form fails to submit. I´m using google chrome Versión 30.0.1599.101 m
This appears in the console: Uncaught NetworkError: Form submission failed.
Here is the app: https://script.google.com/d/1yrgM20n1ZI99bChN2qtQWgGck36OccLN3A16Gn7tCPvsJw0EcK_ql7C5/edit?usp=sharing
Maybe you should add encoding="multipart/form-data" attribute to form tag.
If not solved already – did you try changing the input type from "button" to "submit"? On top of that I'd also try giving it another value than "Submit" since that might interfere with the actual submit parameter.

Play framework 2.04 browser request is hanging once multipartFormData maxlength has been reached. How to solve it?

My server side code is the following (just for the sake of testing it):
def upload = Action(parse.maxLength(maxLength = 10*1024, parser.multipartFormData)) {
implicit request =>
Logger.info("data: " + request.body.dataParts)
Logger.info("file: " + request.body.file("picture"))
Logger.info("req: " + request.contentType)
Logger.info("req body: " + request.body)
Ok("File has been uploaded")
}
My client side code is a simple form that has an input of type file.
#helper.form(action = routes.Application.upload, 'enctype -> "multipart/form-data") {
<p>
<input type="text" name="name" />
</p>
<p>
<input id="imageFile" type="file" name="picture" accept="image/*" />
</p>
<p>
<input type="submit" value="Save" />
</p>
}
The problem is that if you try to upload files that are bigger than 10KB the browser will hang waiting for the server to finish even though it appears that the server has finished consuming the request. How to solve it?
Unfortunately, there seems to be a problem related to this in Play 2.0.4 and the browser will hang waiting for the file to finish uploading even though the request body has been consumed in the server side. A discussion regarding the issue can be found here and it was reported here (play doesn't finish consuming request if maxlength is reached).
Fortunately, this has been resolved in Play 2.1 and the first release candidate is already available. So, the best thing to do would be to migrate your app to Play 2.1.

DOJO 1.8 /dojo/request/iframe is deleting <form></form> when uploading a file

I'm seeing a really strange behavior under DOJO 1.8.0. I'm trying to asynchronously upload a file. The file is uploading just fine and I'm getting the payload as expected, but when clicking the submit button the tags and everything in between is inexplicably deleted! It just vanishes. (NOTE: I've isolated this testing to a test page, so there's nothing else at play that would account for it. You're looking at the entirety of the code.)
require(['dojox/form/Uploader',
"dojo/request/iframe",'dojo/dom','dojo/on',
'dojox/form/uploader/plugins/IFrame', 'dojo/domReady!'],
function(Uploader,iframe,dom,on){
on(dom.byId("myButton"), "click", function(){
iframe.post("UploadFile.php",{
form: dom.byId("myForm"),
handleAs: "json"
}).then(function(data){
console.log(data);
}, function(err){}
);
});
<form method="post" id="myForm" enctype="multipart/form-data" >
<input name="uploadedfile" type="file" data-dojo-type="dojox.form.Uploader"
label="Select Some Files" id="uploader" />
<input id="myButton" type="button" value="Submit" />
</form>
Any ideas from anyone with DOJO 1.8 experience? I've been using /dojo/io/iframe just fine with versions 1.6 thru 1.7. This started happening only with 1.8 using the new /dojo/request/iframe code.
See http://jsfiddle.net/seeds/XD4Dc/1/
The form element is set to have target of dojo's injected iframe. Then form gets like, 'dijitHidden' with abs position -1000 top/left. Cant see why tbh.
There's a fix in the fiddle, add to your callback:
with(dom.byId("myForm").style) {
position = "";
left = "";
top = "";
}
I took this issue to the DOJO-Interest group and it was found to be bug with DOJO 1.8.0. It'll be fixed with the upcoming 1.8.1 release.
http://bugs.dojotoolkit.org/ticket/15939
From the bug report:
The form wasn't getting "eaten", but rather the position was getting set on it and moved out of the viewport because of some faulty logic to check if the form was in the DOM. This has been fixed and should be in 1.8.1.

Ajax call not working in Google gadget

I have a conversion rate script which i know works perfectly outside of a Google gadget however i cannot figure out why it doesn't work inside of a gadget.
Here is my XML:
<?xml version="1.0" encoding="UTF-8"?>
<Module>
<ModulePrefs author="Purefx.co.uk" height="280"></ModulePrefs>
<UserPref name="title" display_name="Widget Title" default_value="Currency Converter"/>
<UserPref name="color" display_name="Widget color" default_value="Color" datatype="enum">
<EnumValue value="Color"/>
<EnumValue value="Black and White"/>
</UserPref>
<UserPref name="style" display_name="Widget Style" default_value="Sidebar" datatype="enum">
<EnumValue value="Sidebar"/>
<EnumValue value="header/footer"/>
</UserPref>
<UserPref name="attribution" display_name="Attribution text" default_value="Purefx" datatype="enum">
<EnumValue value="Purefx"/>
<EnumValue value="Foreign Exchange"/>
<EnumValue value="Currency exchange"/>
</UserPref>
<Content type="html"><![CDATA[
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#convert').click(function(){
//Get all the values
var amount = $('#amount').val();
var from = $('#from').val();
var to = $('#to').val();
//Make data string
var dataString = "amount=" + amount + "&from=" + from + "&to=" + to;
$.ajax({
type: "POST",
url: "ajax_converter.php",
data: dataString,
success: function(data){
//Show results div
$('#results').show();
//Put received response into result div
$('#results').html(data);
}
});
});
});
</script>
]]>
</Content>
</Module>
I haven't included the html part of the content or the php script as that part is 100% working and irrelevant to this problem.
I think the problem is specifically the execution of the Ajax call, on clicking 'convert' nothing is being 'posted' in the firebug console window.
I can't find anything that might suggest i'm missing something so any thoughts are appreciated.
Many thanks in advance
You cannot make direct calls from inside a gadget because a gadget lives inside a gadget container and all calls are proxied by the gadget container.
You must use io.makeRequest to fetch remote data.
More info, see http://code.google.com/apis/gadgets/docs/remote-content.html