Coder Social home page Coder Social logo

valums-file-uploader / file-uploader Goto Github PK

View Code? Open in Web Editor NEW

This project forked from simoneast/file-uploader

320.0 36.0 144.0 709 KB

Multiple file upload plugin for HTML forms. User-friendly progress-bar + uploads via drag-and-drop. Coded in Javascript + AJAX, not Flash. Server-side PHP, Java, & ColdFusion examples included.

Home Page: http://valums-file-uploader.github.com/file-uploader/

License: Other

CSS 2.59% Java 2.62% ColdFusion 2.67% PHP 5.09% JavaScript 70.20% HTML 15.84% Perl 0.99%

file-uploader's Introduction

Notice:
This project made some improvements to Valum's initial AJAX uploader, but it is no longer actively maintained. Some bugs may remain unfixed. A commercial fork of this project (with a licencing fee) with many bugfixes is available at http://fineuploader.com/.
Interested maintainers for this project may post on the issues forum.

Valum's File Uploader v2.0 beta

Welcome! This project attempts to achieve a user-friendly file-uploading experience over the web. It's built as a Javascript plugin for developers looking to incorporate file-uploading into their website.

This is a public fork of Valum's File Uploader (v1) in an attempt to incorporate some of the best bugfixes and patches to make a version compatible with the latest browsers in 2012.

We would love developers to contribute any improvements and bugfixes they produce. See How do I contribute to other's code in GitHub?.

Initiated by SimonEast, but interested maintainers are welcome.

Summary

This plugin uses an XMLHttpRequest (AJAX) for uploading multiple files with a progress-bar in FF3.6+, Safari4+, Chrome and falls back to hidden-iframe-based upload in other browsers (namely IE), providing good user experience everywhere.

It does not use Flash, jQuery, or any external libraries.

Features

  • Multiple file select, progress-bar in FF, Chrome, Safari
  • Drag-and-drop file select in FF, Chrome
  • Uploads are cancellable
  • No external dependencies
  • Doesn't use Flash
  • Fully working with HTTPS
  • Keyboard support in FF, Chrome, Safari
  • Tested in IE7/8, Firefox 3/3.6/4, Safari 4/5, Chrome, and Opera 10.60

License

This plugin is open sourced under GNU GPL 2 or later and GNU LGPL 2 or later.

Known Issues

Plugin breaks back button functionality in Opera.

Getting started

The fileuploader.js contains two classes that are meant to be used directly. If you need a complete upload widget (from demo) to quickly drop into your current design, use qq.FileUploader.

If you want to customize uploader, by using a different looking file list or change the behaviour or functionality use qq.FileUploaderBasic.

The difference between them is that qq.FileUploader provides a list of files, drag-and-drop, but qq.FileUploaderBasic only creates button and handles validation. Basic uploader is easier extendable, and doesn't limit possible customization.

qq.FileUploader extends qq.FileUploaderBasic, so that all the options present in the basic uploader also exist in the full widget.

qq.FileUploader - Setting up full upload widget

Include fileuploader.js and fileuploader.css into your page. Create container element.

<div id="file-uploader">       
<noscript>          
    <p>Please enable JavaScript to use file uploader.</p>
    <!-- or put a simple form for upload here -->
</noscript>         
</div>

Initialize uploader when the DOM is ready. Change the action option. For example ../server/php.php for the default folder structure. In the server folder you will find examples for different platforms. If you can't find the one you need, check the readme.txt in the same folder.

var uploader = new qq.FileUploader({
	// pass the dom node (ex. $(selector)[0] for jQuery users)
	element: document.getElementById('file-uploader'),
	// path to server-side upload script
	action: '/server/upload'
}); 

Options of both classes

    // url of the server-side upload script, should be on the same domain
    action: '/server/upload',
    // additional data to send, name-value pairs
    params: {},
    
    // validation    
    // ex. ['jpg', 'jpeg', 'png', 'gif'] or []
    allowedExtensions: [],        
    // each file size limit in bytes
    // this option isn't supported in all browsers
    sizeLimit: 0, // max size   
    minSizeLimit: 0, // min size
    abortOnFailure: true, // Fail all files if one doesn't meet the criteria
    
    // set to true to output server response to console
    debug: false,
    
    // events         
    // you can return false to abort submit
    onSubmit: function(id, fileName){},
    onProgress: function(id, fileName, loaded, total){},
    onComplete: function(id, fileName, responseJSON){},
    onCancel: function(id, fileName){},
    onError: function(id, fileName, xhr){}
    
    messages: {
        // error messages, see qq.FileUploaderBasic for content            
    },
    showMessage: function(message){ alert(message); }        

Instance methods

  • setParams(newParams)

Changing alert/messages to something more user friendly

If you limited file types and max size, you will probably want to change the default alert and messages as you see fit, this is possible using showMessage callback and messages option.

Sending additional params

To add a parameter that will be passed as a query string with each upload use params option.

    var uploader = new qq.FileUploader({
        element: document.getElementById('file-uploader'),
        action: '/server-side.upload',
        // additional data to send, name-value pairs
        params: {
            param1: 'value1',
            param2: 'value2'
        }
    });

To change params based on the state of your app, use

    uploader.setParams({
       anotherParam: 'value' 
    });

It can be nicely used in onSubmit callback.

Troubleshooting

If you can't get the uploader to work, please try the following steps before asking for help.

If the upload doesn't complete, saying "failed":

  • Set the debug option of the FileUploader to true.
  • Open the page where you have a FileUploader.
  • Open developer console in your browser.
  • Try to upload the file. You should see a server serponse.

It should be {success:true} for completed requests. If it's not, then you have a problem with your server-side script.

Contributors

Thanks to everybody who contributed, either by sending bug reports or donating. And special thanks to:

John Yeary
Sidney Maestre
Patrick Pfeiffer
Sean Sandy (SeanJA)
Andy Newby
Ivan Valles

file-uploader's People

Contributors

asturur avatar bencolon avatar benruijl avatar bjansen avatar danielbeardsley avatar doomhz avatar ebrentnelson avatar gsouf avatar hlship avatar jackdanger avatar justinvw avatar kir avatar pegweb avatar richsage avatar seanja avatar simoneast avatar sstur avatar texasassetprotection avatar thinkscape avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

file-uploader's Issues

Hey! Wondering if you are still interested in maintaining the fork?

If yes, please let me know if you need some help. I would be more than happy to point to this release as a new official version, and highlight all the effort you have put into it.

By the way, I can't find the github's messaging feature anymore. Can you please send me your email to andrew (at) valums.com ?

Need default button style

I want the button area look like my other buttons in the view.
It's rather difficult to get to know default button-style colors, alpha, and so on.
How can I do so?

Problem in IE 8

Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; BTRS130296; GTB7.3; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E)
Timestamp: Thu, 7 Jun 2012 03:12:23 UTC

Message: Access is denied.

Line: 1136
Char: 9
Code: 0
URI: http://localhost/theme/V02/js/valums/client/fileuploader.js

Error at this line : form.submit();

Please help me fix it.

Regards,
TUAN NGO

Use options.inputName in multipart encoding

In multipart encoding, the name of the file input field is currently set as the filename. It would be better if if was the value of options.inputName. X-File-Name header is also not required for multipart handling:

        // build query string
        params = params || {};
        if (this._options.encoding != 'multipart') {
            params[this._options.inputName] = name;
        }
        var queryString = qq.obj2url(params, this._options.action);

        xhr.open("POST", queryString, true);
        xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
        if (this._options.encoding == 'multipart') {
            var formData = new FormData();
            formData.append(this._options.inputName, file);
            file = formData;
        } else {
            xhr.setRequestHeader("X-File-Name", encodeURIComponent(name));
            xhr.setRequestHeader("Content-Type", "application/octet-stream");
            //NOTE: return mime type in xhr works on chrome 16.0.9 firefox 11.0a2
            xhr.setRequestHeader("X-Mime-Type",file.type );
        }

Inline style applied to drop-area in JavaScript.

In our design, we'd like to keep the droparea visible at all times. Currently this is not possible to implement in the uploader, because it hides the drop area manually in JavaScript. This happens in the _setupDropzone() function.

Bower

Hi guys, i aded this awesome plugin in bower package manager.

It was necessary to use in the project. Now that developers can have updates in bower, you need to publish a new version and release a valid semver tag.

bower info valums-file-uploader

Coldfusion 10 - GetHttpRequestData.content always empty

Hi,

i'm working with coldfusion 10 and the example in file-uploader doesn't work. If i upload a file, the content-Object from GetHttpRequestData() is always empty and then coldfusion throws a error that the content-type of the form is invalid (because its application/octet-stream).

This error message is of course understandable, as in ColdFusion code (if len (content) is 0) is normal to upload the file. But I wonder why the content - object is always empty. Does' to already known problems?

Thank you,
Regards Adrian

Valum's file uploader not working over SSL

We have been using Valum's file uploader on the pages of our site served as HTTP, with no problems. We now want to use it on our HTTPS registration page, to allow people to upload a profile pic for their account. The documentation Valum's file uploader says it works with HTTPS, but it seems to be making the AJAX request via HTTP and we're getting the following errors in the console:

OPTIONS http://flooting.com/lib/upload?label=&creationdate=&format=json&type=160x160&session=015b57b5958a7e5141234788ca480b63&collection=&qqfile=IMG_0298.JPG No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://flooting.com' is therefore not allowed access.

XMLHttpRequest cannot load http://flooting.com/lib/upload?label=&creationdate=&format=json&type=160x160&session=015b57b5958a7e5141234788ca480b63&collection=&qqfile=IMG_0298.JPG. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://flooting.com' is therefore not allowed access.

Is there a parameter we can set to make the uploader send the request via HTTPS (we've not been able to find one).

We've tried setting action to //lib/upload (two slashes)
That does force the request to https but we lose the domain from the path. i.e. We see a request to
https://lib/upload?[params] which doesn't work.

Our code is as follows;

    var uploader = new qq.FileUploader({
        // pass the dom node (ex. $(selector)[0] for jQuery users)
        element: [% IF element %][% element %][% ELSE %]document.getElementById('file-uploader')[% END %],
        // path to server-side upload script
        action: '/lib/upload',
        debug: true,
        allowedExtensions: ['jpg', 'jpeg', 'png', 'gif'],
        sizeLimit: 10485760, // max size 10Mb  
        minSizeLimit: 100, 
        showMessage: function(message){ alert(message); },
        onError: function(id, fileName, errorReason) {
            if (errorReason.indexOf("code #6") != -1) {
                warn('No space left');
                alert('Error: You have no space for images left. Please contact support.');
            }
        },
        onComplete: function(id, fileName, responseJSON){
            if( ! responseJSON.filesdata || ! responseJSON.filesdata[0].url)
            {
                console.log(responseJSON);
                //ngn_dump(responseJSON, true, 'responseJSON');
                alert('Error: didn\'t get image url from server.');
            }
            else
            {
                console.log(responseJSON);
                $('#[% id %]').attr('src',responseJSON.filesdata[0].url);
                [% IF fieldname %]
                $('#[% fieldname %]').val(responseJSON.filesdata[0].url);
                [% END %]
            }
        },
        params: {
            label:'',
            creationdate:'',
            format:'json',
            type:"[% rep_type %]",
            session:"[% IF y; y.session.id; ELSE; c.sessionid; END; %]",                
            collection:"[% collectionId || story.id %]",
        }
    });

Works in IE9?

I am wondering if this uploader works in IE9. I have the original version which does not work in IE9. (get unexpected call to method or property access for dataTransfer.EffectsAllowed when trying to drag file into the uploader section)

I would like to move to this version, but will be no point if doesn't work in ie9.

thanks again!

Fine Uploader is MIT licensed once again

FYI: This particular repo is a fork of SimonEast/file-uploader, which itself is a fork of FineUploader/fine-uploader. In other words, Fine Uploader is the parent project. I realize that the readme in Valums-File-Uploader/file-upload claims that Fine Uploader is the fork, but that is not the case - the reverse is in fact true.

Up until recently, Fine Uploader was commercially licensed, which was likely unappealing for all but enterprise users. Starting with Fine Uploader 5.9.0, the project is once again MIT Licensed. In other words, migration back to Fine Uploader is probably a better option than sticking with this particular repo, since it is no longer actively maintained.

Thanks

Just wanted to say thanks for doing this. Sucks when a project gets abandoned.

File Name truncation when the full path length is more than 260 characters

Hey Guys,

We have a scenario where the file name is truncating when the full path length is more than 260 characters. Do you have any thoughts on how we can resolve this issue.
e.g.
actual file name and path- C:\Users\abcdef\Desktop\AAAAAAAAAAAAAAAAAAAAAAAAAAAA\BBBBBBBBBBBBBBBBBBBBBBBBBBBB\CCCCCCCCCCCCCCCCC\DDDDDDDDDDDDDDDDDDDDDDDDDDDDD\EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE\FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF\FileName1111111111111111111111111111111111111111111111111111.txt

File name when uploaded as - FileNa~1.txt

Look forward to your help in resolving this.

Let me know if you need any more details to help.

Thanks and regards,
Pratik Lara

Add support on exiting filename upload

Adding a support on exiting filename upload, the upload should return a modal asking what to do (override, rename, cancel) when a same filename exist on upload.

Methods to control uploads

I was using valums original file uploader, just saw it is no longer maintained and forked here..

BIG question here: How can I cancel uploads? It says in the description they are cancelable.. great.. how? :)

Thing is, I have a chat project where I use a very simple upload file directly to chat functionality. I have a drop down menu where this option (upload file) is available, and a click there gives the file upload requester.. Select a file, and a separate console comes up, where the file upload progress is shown. Once the file is finished, the console disappears again and the file is posted in the chat.

Problem is, if I want to cancel the upload, I'd need a cancel method somewhere. I have not found any. Not in the documentation at least, and currently I am using the original version, and what I have understood from the code is that it basically can only be canceled by clicking on an HTML element that has qq-uploader-cancel.. This is FAR from ideal obviously :)

So in short, I'd like to see some method to control uploads.. It would be VERY nice to just have a JS library that I can control from, say, jQuery

Found bug in code

Faced with error with 'qqfile' parameter sending to server . Spent some time comparing my old version of file and the newest one.
fileupload.js, line 1352. Now it is
formData.append(name, file);

but must be
formData.append(this._options.inputName, file);

because in onld code it was
formData.append('qqfile', file); and this._options.inputName means qqfile by default.

Failed to upload image

On the walkthrough it says Set the debug option of the FileUploader to true.
Open the page where you have a FileUploader.
Open developer console in your browser.
Try to upload the file. You should see a server serponse.

I did this, and there is no difference in what happens. Whenever I try to upload an image it just says failed without any sort of errors popping up. I can't find any documentation on what to do when failed. This is working on another site I have but not on the one im currently working on. Can someone point me in the direction of how to troubleshoot failed uploads?

The script upload files correctly, but server response is always null.

i have used this beauty script in my webapp and files are correctly uploaded, but the server response is always null. it doesnt show if upload has been ok or failed. i know the problem is in the server side, but i cant find it. ¿Does anyone have the same error? excuse me for my bad english !!!

.indexOf issue in ie8

here is function to fix this issue

[].indexOf || (Array.prototype.indexOf = function (v, n) {
n = (n == null) ? 0 : n;
var m = this.length;
for (var i = n; i < m; i++)
if (this[i] == v)
return i;
return -1;
});

FF crashes when I try to upload large file

When I try to upload 90 Mb file in Firefox 27.0 on Mac OS X 10.8.5 browser crashes all the time. Report information:

AdapterDeviceID: 0x 166
AdapterVendorID: 0x8086
Add-ons: %7B6e84150a-d526-41f1-a480-a67d3fed910d%7D:1.5.6,%7Be3f6c2cc-d8db-498c-af6c-499fb211db97%7D:1.12.9.1,%7B972ce4c6-7e08-4474-a285-3208198ce6fd%7D:27.0,jid0-IjImIyAhC6aVwuN2VA4XpGwFbHk%40jetpack:1.5.1,firebug%40software.joehewitt.com:1.12.6,onepassword4%40agilebits.com:4.1.0
BuildID: 20140127194636
CrashTime: 1392315595
EMCheckCompatibility: true
Email:
FramePoisonBase: 7ffffffff0dea000
FramePoisonSize: 4096
InstallTime: 1392193906
Notes: AdapterVendorID: 0x8086, AdapterDeviceID: 0x 166GL Layers! GL Context? GL Context+ GL Layers+
ProductID: {ec8030f7-c20a-464f-9b0e-13a3a9e97384}
ProductName: Firefox
ReleaseChannel: release
SecondsSinceLastCrash: 874
StartupTime: 1392314725
Theme: classic/1.0
Throttleable: 1
URL: wyciwyg://4/http://localhost:8080/author-publisher
Vendor: Mozilla
Version: 27.0
useragent_locale: ru

Who faced with the same problem?

Thanks,
Tamara.

qq.extend issue

Hi, your function is does not merge as it should be...sub-object are not merged
e.g: object "classes"

Sorry for my bad english :(

Great plugin ;)

Resize before upload.

I am trying to implement the re-size before upload, but there is an error "upload failed" int the image preview container. Are you sure the resize function works. Note I use the original valum-file upload and it works fine.

Problem with large file upload

Hello there,

While trying to upload large media files(video files) it gets interrupted and don't get uploaded. I have done many server configuration changes such as upload_max_size, post_max_size, input_post_time but still couldn't resolve the issue. Any help will be greatly appreciated.

Thanks

IE9 problem with the onComplete() in FUB

I'm constantly getting the boolean 'false' with the third parameter of the onComplete() method : responseJSON.success in IE9 (which is the only version of IE I'm testing in).

I'm using the basic version of the plugin and the ajax returns from within the PHP:

try {

// code processing upload
echo json_encode(array('success' => true, 'content' => $image));

} catch (Exception $e) {
$message = $e->getMessage();
echo json_encode(array('success' => false, 'error' => $message));
}

It works fine in Firefox, Chrome etc. - it's just IE that fails.

Is there a problem with the onComplete() method and IE?

toBytes() PHP method

Hi there,

I think your example php file and the method toBytes() is multiplying the value incorrectly within the switch for MB and GB - it uses 1024 for all cases.
I just thought you might want to know that. :)

Broken in FF8, FF13

For some reason, it doesn't work at all in FF 8.

I'm attaching qq.FileUploaderBasic to a <button> element, multiple is off. It inits correctly, attaches event and appends <input type="file"> inside my button.

Unfortunatelly clicking the button does nothing. Works fine in Chrome.

Not working

Hi I followed all steps to setup the file uploader, But can't find the upload button. Please help.

Not working on IE

The problem is that the request on IE gets (pending) status and doesn't uploads anything.
I wanted to try the library using client/demo.htm, but making it upload to server/php.php. Here's how I used it:

client/demo.htm

<script>        
    function createUploader(){            
        var uploader = new qq.FileUploader({
            element: document.getElementById('file-uploader-demo1'),
            action: '/server/php.php',
            debug: true,
            extraDropzones: [qq.getByClass(document, 'qq-upload-extra-drop-area')[0]]
        });           
    }

    // in your app create uploader as soon as the DOM is ready
    // don't wait for the window to load  
    window.onload = createUploader;     
</script>

server/php.php

$allowedExtensions = array('wmv', 'mpg', 'avi', 'mov');
$sizeLimit = 30 * 1024 * 1024;
$uploader = new qqFileUploader($allowedExtensions, $sizeLimit);
$result = $uploader->handleUpload('uploads/');
echo htmlspecialchars(json_encode($result), ENT_NOQUOTES);

Problems with UTF-8 site and perl

I have this one working perfectly on a latin-1 encoded site but on another one, which is UTF-8, the images are corrupted and not properly uploaded. I'm sure the error is somewhere in my UTF-8 workflow for perl but I just can't find it. Has someone experienced this?

Bootstrap template

Hi,

are you using bootstrap with file uploader, please? If yes, could you paste here what you have in template, fileTemplate and classes options? Thank you!

Petr

Not working on windows

I have used your plug-in in my web site. Its working good on Ubuntu machine with all major browsers but when i am using it on windows machine, though i can upload file with normal upload button but i could not able to use drag and upload file feature for this plug-in.

And i have tested it on your demo url: http://valums-file-uploader.github.io/file-uploader/

I will appreciate your help for this.

Thanks

Upload fails on Struts app

Hello,

The lines of code need modifying below for it to work:

if (this._options.encoding == 'multipart') {
var formData = new FormData();
/* formData.append(name, file); */ <<<< Removed
formData.append(this._options.inputName, file); <<< Added
file = formData;
} else {
....
}

Also need to add encoding: 'multipart' to the qq.FileUploader page options.

Cheers

Keep order in multiple upload

Is there any option to keep order when doing multiple selection? Already tried with maxConnections: 1, but instead of ordering it chooses a random entry to upload.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.