A file input button for all browsers, is this possible?

I can’t remember the source of the technique but this seems to be cross-browser. Tested in: Google Chrome 9 FireFox 3.6 Internet Explorer 6-9 Opera 10 Safari for Windows Here is the complete code: HTML: <div> <button><!– this is skinnable –>Pick a file …</button> <input type=”file” /> </div> CSS: div { position:relative; width: 100px; height: … Read more

Asp.Net Check file size before upload

ASPX <asp:CustomValidator ID=”customValidatorUpload” runat=”server” ErrorMessage=”” ControlToValidate=”fileUpload” ClientValidationFunction=”setUploadButtonState();” /> <asp:Button ID=”button_fileUpload” runat=”server” Text=”Upload File” OnClick=”button_fileUpload_Click” Enabled=”false” /> <asp:Label ID=”lbl_uploadMessage” runat=”server” Text=”” /> jQuery function setUploadButtonState() { var maxFileSize = 4194304; // 4MB -> 4 * 1024 * 1024 var fileUpload = $(‘#fileUpload’); if (fileUpload.val() == ”) { return false; } else { if (fileUpload[0].files[0].size < maxFileSize) … Read more

javascript: upload image file and draw it into a canvas

const EL = (sel) => document.querySelector(sel); const ctx = EL(“#canvas”).getContext(“2d”); function readImage() { if (!this.files || !this.files[0]) return; const FR = new FileReader(); FR.addEventListener(“load”, (evt) => { const img = new Image(); img.addEventListener(“load”, () => { ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height); ctx.drawImage(img, 0, 0); }); img.src = evt.target.result; }); FR.readAsDataURL(this.files[0]); } EL(“#fileUpload”).addEventListener(“change”, readImage); canvas {display: block;} … Read more

What’s the best way to create a single-file upload form using PHP?

File Upload Tutorial HTML <form enctype=”multipart/form-data” action=”action.php” method=”POST”> <input type=”hidden” name=”MAX_FILE_SIZE” value=”1000000″ /> <input name=”userfile” type=”file” /> <input type=”submit” value=”Go” /> </form> action.php is the name of a PHP file that will process the upload (shown below) MAX_FILE_SIZE must appear immediately before the input with type file. This value can easily be manipulated on the … Read more

Node.js: how to limit the HTTP request size and upload file size?

Just an update (07-2014), as I’m not able to add comments: As correctly noted above, newer Express versions have deprecated the use of the limit middleware and now provide it as a built-in option for the BodyParser middleware: var express = require(‘express’) var bodyParser = require(‘body-parser’) var app = express() app.use(bodyParser.json({ limit: ‘5mb’ }))

Android WebView File Upload

This is how i am using in my app private class MyWebChromeClient extends WebChromeClient { //The undocumented magic method override //Eclipse will swear at you if you try to put @Override here // For Android 3.0+ public void openFileChooser(ValueCallback uploadMsg, String acceptType) { mUploadMessage = uploadMsg; Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.addCategory(Intent.CATEGORY_OPENABLE); intent.setType(“*/*”); startActivityForResult(Intent.createChooser(intent, “File … Read more

Meteor: uploading file from client to Mongo collection vs file system vs GridFS

You can achieve file uploading with Meteor without using any more packages or a third party Option 1: DDP, saving file to a mongo collection /*** client.js ***/ // asign a change event into input tag ‘change input’ : function(event,template){ var file = event.target.files[0]; //assuming 1 file only if (!file) return; var reader = new … Read more