<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Techie-Gyan &#187; fileupload</title>
	<atom:link href="http://www.techiegyan.com/category/fileupload/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.techiegyan.com</link>
	<description></description>
	<lastBuildDate>Fri, 25 Nov 2011 05:37:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>File upload using Ajax &#8211; Jquery Plugin</title>
		<link>http://www.techiegyan.com/2009/10/03/file-upload-using-ajax-jquery-plugin/</link>
		<comments>http://www.techiegyan.com/2009/10/03/file-upload-using-ajax-jquery-plugin/#comments</comments>
		<pubDate>Sat, 03 Oct 2009 19:28:28 +0000</pubDate>
		<dc:creator>Aditya</dc:creator>
				<category><![CDATA[ajax]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[fileupload]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://www.techiegyan.com/?p=922</guid>
		<description><![CDATA[I have already written about the Ajax file upload on this blog and found this another plug-in of Jquery for Ajax file upload. Looks like an evolved plug-in with nice demonstrations and documentation at their home page. This is called Uploadify, you can check this out at www.uploadify.com Let me just try to describe this [...]]]></description>
			<content:encoded><![CDATA[<p>I have already written about the <a href="http://www.techiegyan.com/?p=42">Ajax file upload on this blog</a> and found this another plug-in of Jquery for Ajax file upload. Looks like an evolved plug-in with nice demonstrations and documentation at their home page. This is called <strong>Uploadify</strong>, you can check this out at <a href="http://www.uploadify.com/" target="_blank">www.uploadify.com</a></p>
<p>Let me just try to describe this plug-in and see how easily can any one use it</p>
<p>This plug-in allows user to upload files using Ajax. Plug-in has many features which were generally asked by people for earlier Ajax upload plug-ins like </p>
<p>a. Integrated progress bar<br />
b. passing extra/more parameters with Ajax file upload request<br />
c. Multiple Ajax file uploads and queuing them.<br />
d. Limiting upload size of file<br />
e. Canceling Ajax upload in between. </p>
<p>Plug-in also allows you to customize the behavior by providing number of callback functions which can be used for adding custom functionality. See the <a href="http://www.uploadify.com/documentation/" target="_blank">complete documentation</a> for more details. </p>
<p>Following are the pre-requisites of this plug-in </p>
<p>1. jQuery v1.2.x or greater<br />
2. SWFObject v2.2 or greater<br />
3. Flash Player v9.0.24 or greater</p>
<p>Now lets try to do some samples of it. You can also check out the demo page of the <a href="http://www.uploadify.com/" target="_blank">www.uploadify.com</a> for samples.</p>
<p><iframe frameborder="0" src="http://www.techiegyan.com/examples/uploadify/example/index.php" width="520" height="150"</iframe></p>
]]></content:encoded>
			<wfw:commentRss>http://www.techiegyan.com/2009/10/03/file-upload-using-ajax-jquery-plugin/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Free FTP Clients &#8212; File Transfer</title>
		<link>http://www.techiegyan.com/2009/06/10/free-ftp-clients-file-transfer/</link>
		<comments>http://www.techiegyan.com/2009/06/10/free-ftp-clients-file-transfer/#comments</comments>
		<pubDate>Wed, 10 Jun 2009 18:09:22 +0000</pubDate>
		<dc:creator>Aditya</dc:creator>
				<category><![CDATA[addon]]></category>
		<category><![CDATA[fileupload]]></category>
		<category><![CDATA[technology]]></category>
		<category><![CDATA[tool]]></category>

		<guid isPermaLink="false">http://www.techiegyan.com/?p=747</guid>
		<description><![CDATA[FTP stands for File Transfer Protocol which become synonymous to the action of transferring your file using FTP. People generally refer like &#8216;FTP this tar file to xyz public server&#8217;. As internet grown so rapid in past few years, web pages become the most popular application for the users. This promoted use of HTTP for [...]]]></description>
			<content:encoded><![CDATA[<p>FTP stands for <a href="http://en.wikipedia.org/wiki/File_Transfer_Protocol">File Transfer Protocol</a> which become synonymous to the action of transferring your file using FTP. People generally refer like &#8216;FTP this tar file to xyz public server&#8217;. As internet grown so rapid in past few years, web pages become the most popular application for the users. This promoted use of HTTP for file transfer also, but still FTP is generally used when you want to transfer files reliably. </p>
<p>The best way to use FTP is using command line client which works really well on all platforms.For UI people, here I am listing some of the free FTP clients which can be used for getting files from FTP server or putting files to FTP Server, Most of them are similar in functionality but some have better features like using multiple connection in background or uploading multiple files together :</p>
<p>1. WinSCP <a href="http://winscp.net/eng/index.php">http://winscp.net/eng/index.php</a><br />
2. Fire FTP <a href="http://fireftp.mozdev.org/">http://fireftp.mozdev.org/</a><br />
3. File Zilla <a href="http://filezilla-project.org/">http://filezilla-project.org/</a><br />
4. Smart FTP : <a href="http://www.smartftp.com/">http://www.smartftp.com/</a><br />
5. Core FTP : <a href="http://www.coreftp.com/">http://www.coreftp.com/</a><br />
6. Go FTP : <a href="http://www.goftp.com/">http://www.goftp.com/</a></p>
<p>Most of the above are installations which will provide you another program to connect to FTP server and then do file transactions. Fire FTP is quite handy and it not a separate program but an addon to Mozilla Firefox. Most of them are open source also. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.techiegyan.com/2009/06/10/free-ftp-clients-file-transfer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Jquery Ajax upload with Progress bar &#8211; Spring Framework</title>
		<link>http://www.techiegyan.com/2009/04/25/jquery-ajax-upload-with-progress-bar-spring-framework/</link>
		<comments>http://www.techiegyan.com/2009/04/25/jquery-ajax-upload-with-progress-bar-spring-framework/#comments</comments>
		<pubDate>Sat, 25 Apr 2009 09:25:36 +0000</pubDate>
		<dc:creator>Aditya</dc:creator>
				<category><![CDATA[addon]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[fileupload]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://www.techiegyan.com/?p=499</guid>
		<description><![CDATA[I posted about how to limit the file size while uploading it recently. File upload can be a time taking process in following two cases: a. You are uploading a large file b. Your connection speed is slow In both cases it is good to show progress of file upload to the user as it [...]]]></description>
			<content:encoded><![CDATA[<p>I posted about how to <a href="http://www.techiegyan.com/?p=588">limit the file size while uploading it</a> recently. File upload can be a time taking process in following two cases:</p>
<p>a. You are uploading a large file<br />
b. Your connection speed is slow</p>
<p>In both cases it is good to show progress of file upload to the user as it shows him exactly how much to wait before proceeding to next action. Using the same set of files at back-end (if your are using Spring framework) we can show the progress of file upload. </p>
<p>I did this using following things:</p>
<p><strong>1.</strong> <a href="http://www.jquery.com" target="_blank">JQuery</a><br />
<strong>2.</strong> <a href="http://www.techiegyan.com/?p=42">ajaxfileupload plugin of JQuery</a><br />
<strong>3.</strong> <a href="http://t.wits.sg/tag/progressbar/" target="_blank">jQuery Progress bar plugin </a><br />
<strong>4.</strong> Some changes/additions in the <a href="http://www.techiegyan.com/?p=588">code which was posted in my previous post</a>. </p>
<p><strong>Step 1:</strong> Write a controller which will return the upload progress information to HTML page so that Page javascript can show progress bar accordingly. In the previous post i have given <a href="http://www.techiegyan.com/?p=588">code for AjaxProgressListener</a> which sets the file upload progress information in session object. This Controller will use the session object to get progress information and return it to page. </p>
<div style="overflow:auto">
<pre class="java">&nbsp;
<span style="color: #000000; font-weight: bold;">package</span> com.<span style="color: #006600;">controllers</span>;
&nbsp;
<span style="color: #a1a100;">import javax.servlet.http.HttpServletRequest;</span>
<span style="color: #a1a100;">import javax.servlet.http.HttpServletResponse;</span>
<span style="color: #a1a100;">import javax.servlet.http.HttpSession;</span>
&nbsp;
<span style="color: #a1a100;">import net.sf.json.JSONObject;</span>
&nbsp;
<span style="color: #a1a100;">import org.apache.commons.logging.Log;</span>
<span style="color: #a1a100;">import org.apache.commons.logging.LogFactory;</span>
<span style="color: #a1a100;">import org.springframework.validation.BindException;</span>
<span style="color: #a1a100;">import org.springframework.web.servlet.ModelAndView;</span>
<span style="color: #a1a100;">import org.springframework.web.servlet.mvc.AbstractCommandController;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> UploadInfoController <span style="color: #000000; font-weight: bold;">extends</span> AbstractCommandController <span style="color: #66cc66;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000000; font-weight: bold;">static</span> Log logger = LogFactory.<span style="color: #006600;">getLog</span><span style="color: #66cc66;">&#40;</span>UploadInfoController.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #000000; font-weight: bold;">public</span> UploadInfoController<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        setCommandClass<span style="color: #66cc66;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AObject+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #aaaadd; font-weight: bold;">Object</span></a>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
	@Override
	<span style="color: #000000; font-weight: bold;">protected</span> ModelAndView handle<span style="color: #66cc66;">&#40;</span>HttpServletRequest request, HttpServletResponse response, <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AObject+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #aaaadd; font-weight: bold;">Object</span></a> command, <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3ABindException+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #aaaadd; font-weight: bold;">BindException</span></a> errors<span style="color: #66cc66;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AException+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #aaaadd; font-weight: bold;">Exception</span></a> <span style="color: #66cc66;">&#123;</span>
		JSONObject jsonResp = <span style="color: #000000; font-weight: bold;">new</span> JSONObject<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #66cc66;">&#123;</span>
			HttpSession session = request.<span style="color: #006600;">getSession</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			jsonResp.<span style="color: #006600;">put</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;progressMap&quot;</span>, session.<span style="color: #006600;">getAttribute</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;progressMap&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
			jsonResp.<span style="color: #006600;">put</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;result&quot;</span>, session.<span style="color: #006600;">getAttribute</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;progressStatus&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #66cc66;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AException+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #aaaadd; font-weight: bold;">Exception</span></a> e<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
			logger.<span style="color: #006600;">error</span><span style="color: #66cc66;">&#40;</span>e<span style="color: #66cc66;">&#41;</span>;
			jsonResp.<span style="color: #006600;">put</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;result&quot;</span>, <span style="color: #ff0000;">&quot;error&quot;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span> <span style="color: #000000; font-weight: bold;">finally</span> <span style="color: #66cc66;">&#123;</span>
			response.<span style="color: #006600;">getWriter</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">print</span><span style="color: #66cc66;">&#40;</span>jsonResp<span style="color: #66cc66;">&#41;</span>;
            response.<span style="color: #006600;">flushBuffer</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
		<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">null</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;
&nbsp;</pre>
</div>
<p>Needless to say that entry of this controller will be required in your-app.xml  as bean and then as url mappings section so that HTML page can access this controller using the mapping path.</p>
<p><strong>Step 2 :</strong> While uploading file using ajaxfile upload also use the jquery progress bar plugin. I used it in following way: </p>
<div style="overflow:auto">
<pre class="javascript">&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> showUploadProgress<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
	$<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;#upload_bar&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">show</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	$<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;#upload_bar&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">progressBar</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#123;</span>barImage: <span style="color: #3366CC;">'../images/progressbg_green.gif'</span>, boxImage: <span style="color: #3366CC;">'../images/progressbar.gif'</span>, width:<span style="color: #CC0000;">300</span>, height:<span style="color: #CC0000;">17</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #003366; font-weight: bold;">var</span> uploadInfo = <span style="color: #003366; font-weight: bold;">function</span> getUploadInfo<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		$.<span style="color: #006600;">ajax</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#123;</span>
			url: <span style="color: #3366CC;">'../portal/uploadInfo'</span>,
			type: <span style="color: #3366CC;">&quot;POST&quot;</span>,
			cache: <span style="color: #003366; font-weight: bold;">false</span>,
			dataType: <span style="color: #3366CC;">&quot;json&quot;</span>,
			async: <span style="color: #003366; font-weight: bold;">false</span>,
			success: <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>msg<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
				<span style="color: #000066; font-weight: bold;">if</span><span style="color: #66cc66;">&#40;</span>msg.<span style="color: #006600;">result</span> == <span style="color: #3366CC;">'UPLOADING'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
					<span style="color: #003366; font-weight: bold;">var</span> progressMap = msg.<span style="color: #006600;">progressMap</span>;
					<span style="color: #003366; font-weight: bold;">var</span> progressVal = <span style="color: #66cc66;">&#40;</span>progressMap.<span style="color: #006600;">bytesRead</span>/progressMap.<span style="color: #006600;">contentLength</span><span style="color: #66cc66;">&#41;</span> * <span style="color: #CC0000;">100</span>;
					$<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;#upload_bar&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">progressBar</span><span style="color: #66cc66;">&#40;</span>progressVal<span style="color: #66cc66;">&#41;</span>;
				<span style="color: #66cc66;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span><span style="color: #66cc66;">&#40;</span>msg.<span style="color: #006600;">result</span> == <span style="color: #3366CC;">'DONE'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
					$<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;#upload_bar&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">hide</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
					clearInterval<span style="color: #66cc66;">&#40;</span>uploadInfoHandle<span style="color: #66cc66;">&#41;</span>;
				<span style="color: #66cc66;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span><span style="color: #66cc66;">&#40;</span>msg.<span style="color: #006600;">result</span> == <span style="color: #3366CC;">'MAX_SIZE_EXCEEDS'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
					clearInterval<span style="color: #66cc66;">&#40;</span>uploadInfoHandle<span style="color: #66cc66;">&#41;</span>;
					$<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;#upload_bar&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">hide</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
					showErrorMsg<span style="color: #66cc66;">&#40;</span>getI18N<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;importleads.upload_10mb&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
				<span style="color: #66cc66;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #66cc66;">&#123;</span>
					clearInterval<span style="color: #66cc66;">&#40;</span>uploadInfoHandle<span style="color: #66cc66;">&#41;</span>;
					showErrorMsg<span style="color: #66cc66;">&#40;</span>msg<span style="color: #66cc66;">&#41;</span>;
				<span style="color: #66cc66;">&#125;</span>
			<span style="color: #66cc66;">&#125;</span>,
			error: <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>msg<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
				clearInterval<span style="color: #66cc66;">&#40;</span>uploadInfoHandle<span style="color: #66cc66;">&#41;</span>;
				showErrorMsg<span style="color: #66cc66;">&#40;</span>getI18N<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;importleads.unknown_error&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span>
		<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>;
	<span style="color: #003366; font-weight: bold;">var</span> uploadInfoHandle = setInterval<span style="color: #66cc66;">&#40;</span>uploadInfo, <span style="color: #CC0000;">2000</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre>
</div>
<p>Use the function above while uploading your file using ajaxfileupload plugin. </p>
<pre class="javascript">&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> ajaxFileUpload<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
	showUploadProgress<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	$.<span style="color: #006600;">ajaxFileUpload</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#123;</span>
		url:serverurl,
		secureuri:<span style="color: #003366; font-weight: bold;">false</span>,
		fileElementId:<span style="color: #3366CC;">'file'</span>,
		dataType: <span style="color: #3366CC;">'json'</span>,
		success: <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span>data<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
			<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #66cc66;">&#40;</span>data.<span style="color: #006600;">result</span> == <span style="color: #3366CC;">'success'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
				<span style="color: #009900; font-style: italic;">//Show Success</span>
			<span style="color: #66cc66;">&#125;</span>
			<span style="color: #000066; font-weight: bold;">if</span><span style="color: #66cc66;">&#40;</span>data.<span style="color: #006600;">result</span> == <span style="color: #3366CC;">'error'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
				<span style="color: #009900; font-style: italic;">//Show error</span>
			<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #66cc66;">&#125;</span>,
		error: <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span>data<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
			<span style="color: #009900; font-style: italic;">//Show error</span>
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.techiegyan.com/2009/04/25/jquery-ajax-upload-with-progress-bar-spring-framework/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Limiting upload file size &#8211; Spring</title>
		<link>http://www.techiegyan.com/2009/04/20/limiting-upload-file-size-spring/</link>
		<comments>http://www.techiegyan.com/2009/04/20/limiting-upload-file-size-spring/#comments</comments>
		<pubDate>Mon, 20 Apr 2009 05:50:39 +0000</pubDate>
		<dc:creator>Aditya</dc:creator>
				<category><![CDATA[addon]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[fileupload]]></category>
		<category><![CDATA[j2ee]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[servlet]]></category>
		<category><![CDATA[tomcat]]></category>

		<guid isPermaLink="false">http://www.techiegyan.com/?p=588</guid>
		<description><![CDATA[You might want to limit the size of file to be uploaded on your website as it eats up some of the bandwidth and this can cause problem to rest of the users of your site. Most of the time we do processing on files when they are uploaded on server and content validations has [...]]]></description>
			<content:encoded><![CDATA[<p>You might want to limit the size of file to be uploaded on your website as it eats up some of the bandwidth and this can cause problem to rest of the users of your site. Most of the time we do processing on files when they are uploaded on server and content validations has limitations on client side as you can not read files using javascript on client side (i.e. web browser). </p>
<p>Limit on upload size makes more sense for specific purposes on your website when you know about expected size of file beforehand like image upload websites etc. </p>
<p>If you are using Spring framework for your project/product you can do this using latest version of commons-fileupload which lets you write your own ProgressListener using which you can limit file upload size and monitor the upload process as well. We are using Ajax in our project and for file upload we are using ajaxfileupload (<a href="http://www.techiegyan.com/?p=42">see more in detail</a>)</p>
<p>Following things need to be done for achieving the goal:</p>
<p><strong>1. Implement the ProgressListener for your application like below by implementing org.apache.commons.fileupload.progresslistener </strong></p>
<div style="overflow:auto">
<pre class="java">&nbsp;
<span style="color: #000000; font-weight: bold;">package</span> com.<span style="color: #006600;">listener</span>;
&nbsp;
<span style="color: #a1a100;">import javax.servlet.http.HttpSession;</span>
<span style="color: #a1a100;">import net.sf.json.JSONObject;</span>
<span style="color: #a1a100;">import org.apache.commons.fileupload.ProgressListener;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> AjaxProgressListener <span style="color: #000000; font-weight: bold;">implements</span> ProgressListener <span style="color: #66cc66;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AString+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #aaaadd; font-weight: bold;">String</span></a> STATUS_UPLOADING = <span style="color: #ff0000;">&quot;UPLOADING&quot;</span>;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AString+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #aaaadd; font-weight: bold;">String</span></a> STATUS_FAILED = <span style="color: #ff0000;">&quot;FAILED&quot;</span>;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AString+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #aaaadd; font-weight: bold;">String</span></a> STATUS_DONE = <span style="color: #ff0000;">&quot;DONE&quot;</span>;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AString+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #aaaadd; font-weight: bold;">String</span></a> STATUS_MAX_SIZE_EXCEEDS = <span style="color: #ff0000;">&quot;MAX_SIZE_EXCEEDS&quot;</span>;
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> HttpSession session;
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">void</span> setSession<span style="color: #66cc66;">&#40;</span>HttpSession session<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006600;">session</span> = session;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">void</span> updateStatus<span style="color: #66cc66;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AString+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #aaaadd; font-weight: bold;">String</span></a> status<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
	session.<span style="color: #006600;">setAttribute</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;progressStatus&quot;</span>, status<span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">void</span> update<span style="color: #66cc66;">&#40;</span><span style="color: #993333;">long</span> bytesRead, <span style="color: #993333;">long</span> contentLength, <span style="color: #993333;">int</span> item<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        JSONObject progressMap = <span style="color: #000000; font-weight: bold;">new</span> JSONObject<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	progressMap.<span style="color: #006600;">set</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;bytesRead&quot;</span>, bytesRead<span style="color: #66cc66;">&#41;</span>;
	progressMap.<span style="color: #006600;">set</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;contentLength&quot;</span>, contentLength<span style="color: #66cc66;">&#41;</span>;
	progressMap.<span style="color: #006600;">set</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;item&quot;</span>, item<span style="color: #66cc66;">&#41;</span>;
	session.<span style="color: #006600;">setAttribute</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;progressMap&quot;</span>, progressMap<span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>bytesRead == contentLength<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		session.<span style="color: #006600;">setAttribute</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;progressStatus&quot;</span>, STATUS_DONE<span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
    <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre>
</div>
<p>Progress Listener will read the status of file upload using http request and will set a parameter map in session object so that it can be used for monitoring.<br />
<br/><br />
<strong>2. Extend the CommonsMultipartResolver provided by Spring framework and use the ProgressListener implemented to check the size of upload. </strong></p>
<div style="overflow:auto">
<pre class="java">&nbsp;
<span style="color: #000000; font-weight: bold;">package</span> com.<span style="color: #006600;">resolver</span>;
&nbsp;
<span style="color: #a1a100;">import javax.servlet.http.HttpServletRequest;</span>
<span style="color: #a1a100;">import org.apache.commons.fileupload.FileItemFactory;</span>
<span style="color: #a1a100;">import org.apache.commons.fileupload.FileUpload;</span>
<span style="color: #a1a100;">import org.springframework.web.multipart.MaxUploadSizeExceededException;</span>
<span style="color: #a1a100;">import org.springframework.web.multipart.MultipartException;</span>
<span style="color: #a1a100;">import org.springframework.web.multipart.MultipartHttpServletRequest;</span>
<span style="color: #a1a100;">import org.springframework.web.multipart.commons.CommonsMultipartResolver;</span>
&nbsp;
<span style="color: #a1a100;">import com.listener.AjaxProgressListener;</span>
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> AjaxMultipartResolver <span style="color: #000000; font-weight: bold;">extends</span> CommonsMultipartResolver <span style="color: #66cc66;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">private</span> AjaxProgressListener progressListener;
    <span style="color: #000000; font-weight: bold;">private</span> HttpServletRequest httpServletRequest;
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">void</span> setProgressListener<span style="color: #66cc66;">&#40;</span>AjaxProgressListener progressListener<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006600;">progressListener</span> = progressListener;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> AjaxProgressListener getProgressListener<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> progressListener;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> MultipartHttpServletRequest resolveMultipart<span style="color: #66cc66;">&#40;</span>HttpServletRequest request<span style="color: #66cc66;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> MultipartException <span style="color: #66cc66;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #66cc66;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006600;">httpServletRequest</span> = request;
&nbsp;
            <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006600;">resolveMultipart</span><span style="color: #66cc66;">&#40;</span>request<span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span><span style="color: #66cc66;">&#40;</span>MaxUploadSizeExceededException ex<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        	 <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006600;">progressListener</span>.<span style="color: #006600;">updateStatus</span><span style="color: #66cc66;">&#40;</span>AjaxProgressListener.<span style="color: #006600;">STATUS_MAX_SIZE_EXCEEDS</span><span style="color: #66cc66;">&#41;</span>;
             <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> MultipartException<span style="color: #66cc66;">&#40;</span>ex.<span style="color: #006600;">getMessage</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #66cc66;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AException+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #aaaadd; font-weight: bold;">Exception</span></a> ex<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
            <span style="color: #808080; font-style: italic;">//exception is typically thrown when user hits stop or cancel</span>
            <span style="color: #808080; font-style: italic;">//button halfway through upload</span>
            <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006600;">progressListener</span>.<span style="color: #006600;">updateStatus</span><span style="color: #66cc66;">&#40;</span>AjaxProgressListener.<span style="color: #006600;">STATUS_FAILED</span><span style="color: #66cc66;">&#41;</span>;
            <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> MultipartException<span style="color: #66cc66;">&#40;</span>ex.<span style="color: #006600;">getMessage</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>
    <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;
&nbsp;</pre>
</div>
<p><br/><br />
<strong>3. Update your application-beans.xml for your custom MultipartResolver written in step 2 and re-start the server. </strong></p>
<div style="overflow:auto">
<pre class="xml">&nbsp;
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;multipartResolver&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;com.resolver.AjaxMultipartResolver&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;maxInMemorySize&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- Max in memory 10kbytes --&gt;</span></span>
		<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;value<span style="font-weight: bold; color: black;">&gt;</span></span></span>10240<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/value<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/property<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;maxUploadSize&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!--  10 MB Max upload size --&gt;</span></span>
		<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;value<span style="font-weight: bold; color: black;">&gt;</span></span></span>1024000000<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/value<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/property<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!--
        &lt;property name=&quot;uploadTempDir&quot;&gt;</span>
</span>
		<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;value<span style="font-weight: bold; color: black;">&gt;</span></span></span>/tmp<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/value<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/property<span style="font-weight: bold; color: black;">&gt;</span></span></span>
        --&gt;
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;progressListener&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
		<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;ref</span> <span style="color: #000066;">bean</span>=<span style="color: #ff0000;">&quot;progressListener&quot;</span> <span style="font-weight: bold; color: black;">/&gt;</span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/property<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/bean<span style="font-weight: bold; color: black;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;progressListener&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;com.listener.AjaxProgressListener&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
&nbsp;</pre>
</div>
<p><br/><br />
 These values will be used for checking the file upload size and will automatically be set in AjaxMultipartResolver at the time of server start. Change these values according to your need. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.techiegyan.com/2009/04/20/limiting-upload-file-size-spring/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

