trigger file upload dialog using javascript/jquery

You mean something like this? http://jsfiddle.net/CSvjw/ $(‘input[type=text]’).click(function() { $(‘input[type=file]’).trigger(‘click’); }); $(‘input[type=file]’).change(function() { $(‘input[type=text]’).val($(this).val()); }); Note, though, that the value given by the file input is fake for security reasons. If you want to just have the file name show up, you can cut out the slashes. Here’s an example of how to do it using … Read more

UnicodeEncodeError: ‘ascii’ codec can’t encode character

For anyone encountering this problem when running Django with Supervisor, the solution is to add e.g. the following to the supervisord section of Supervisor’s configuration: environment=LANG=”en_US.utf8″, LC_ALL=”en_US.UTF-8″, LC_LANG=”en_US.UTF-8″ This solved the problem for me in Supervisor 3.0a8 running on Debian Squeeze. Also make sure Supervisor re-reads the configuration by running: supervisorctl reread supervisorctl restart myservice … Read more

What is the most secure method for uploading a file?

Allow only authorized users to upload a file. You can add a captcha as well to hinder primitive bots. First of all, set the MAX_FILE_SIZE in your upload form, and set the maximum file size and count on the server as well. ini_set(‘post_max_size’, ’40M’); //or bigger by multiple files ini_set(‘upload_max_filesize’, ’40M’); ini_set(‘max_file_uploads’, 10); Do size … Read more

FileReader vs. window.URL.createObjectURL

There is difference. time createObjectURL is synchronously executed (immediately) FileReader.readAsDataURL is asynchronously executed (after some time) memory usage createObjectURL returns url with hash, and store object in memory until document triggers unload event (e.g. document close) or execute revokeObjectURL FileReader.readAsDataURL returns base64 that contains many characters, and use more memory than blob url, but removes … Read more

ASP.NET File Upload

1.Create Uploadfile.aspx, code as below: <%@ Page Language=”C#” AutoEventWireup=”true” CodeFile=”Uploadfile.aspx.cs” Inherits=”Uploadfile” %> <!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”> <html xmlns=”http://www.w3.org/1999/xhtml”> <head runat=”server”> <title>File Upload Control</title> </head> <body> <form id=”form1″ runat=”server”> <div> <asp:FileUpload runat=”server” ID=”fuSample” /> <asp:Button runat=”server” ID=”btnUpload” Text=”Upload” onclick=”btnUpload_Click” /> <asp:Label runat=”server” ID=”lblMessage” Text=””></asp:Label> </div> </form> </body> </html> 2.create Uploadfile.aspx.cs, code as … Read more

How to use HttpServletRequest#getParts() in a servlet filter running on Tomcat?

In order to get HttpServletRequest#getParts() to work in a Filter in Tomcat, you need to set allowCasualMultipartParsing=”true” in the webapp’s <Context> element in Webapp/META-INF/context.xml or Tomcat/conf/server.xml. <Context … allowCasualMultipartParsing=”true”> Because as per the servlet 3.0 specification the HttpServletRequest#getParts() should only be available inside a HttpServlet with the @MultipartConfig annotation. See also the documentation of the … Read more