{"id":19951323,"url":"https://github.com/benpptung/file-button","last_synced_at":"2025-06-14T23:03:50.795Z","repository":{"id":31949412,"uuid":"35519214","full_name":"benpptung/file-button","owner":"benpptung","description":"Turn a DOM element into a file input","archived":false,"fork":false,"pushed_at":"2018-05-24T06:00:20.000Z","size":79,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-05-12T07:43:31.591Z","etag":null,"topics":["es5-javascript","file-upload","javascript"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/benpptung.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-05-13T00:18:21.000Z","updated_at":"2018-05-24T06:00:21.000Z","dependencies_parsed_at":"2022-08-24T10:30:50.372Z","dependency_job_id":null,"html_url":"https://github.com/benpptung/file-button","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/benpptung/file-button","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benpptung%2Ffile-button","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benpptung%2Ffile-button/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benpptung%2Ffile-button/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benpptung%2Ffile-button/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/benpptung","download_url":"https://codeload.github.com/benpptung/file-button/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benpptung%2Ffile-button/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259515786,"owners_count":22870129,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["es5-javascript","file-upload","javascript"],"created_at":"2024-11-13T01:07:39.841Z","updated_at":"2025-06-14T23:03:50.769Z","avatar_url":"https://github.com/benpptung.png","language":"JavaScript","readme":"Example\n=======\n\n\n##### javascript\n```\nvar filebutton = require('file-button');\nvar request = require('superagent');\n\nfilebutton\n  .create()\n  .on('fileinput', function(fileinput){\n  \n    var req = request.post('/upload/')\n    var files = fileinput.files;\n    var file;\n    \n    for(var i = 0, len = files.length; i \u003c len; ++i){\n      var file = files[i];\n      req.attach('ajaxfile-' + i, file, file.name);\n    }\n    \n    req\n      .on('progress', function(e){\n      \n        if (e.lengthComputable) {\n        \n        \t// handle progress bar here\n        }\n      })\n      .end(function(err, res) {\n      \n        if (res.ok) {\n        \n           // handle successful result here\n        }\n      });\n    \n  })\n  .mount(document.getElementById('button'));\n\n```\n\n##### html\n\n```\n\u003ca id=\"button\" \u003eUpload\u003c/a\u003e\n```\n  \n  or\n```  \n\u003cdiv id = \"button\"\u003eUpload\u003c/div\u003e\n```\n  \n  or\n```  \n\u003cbutton id=\"button\"\u003eUpload\u003c/button\u003e // IE8 won't work\n```\n\n# Test\n\n```\n$ npm test\n```\n\n# Basic\n\n```\nvar filebutton = require('file-button');\n\nfilebutton\n  .create() // create the instance\n  .on('fileinput', listener) // listen to the event `fileinput`\n  .mount(el); // mount the view on the button\n\n```\n\n# API\n\n### FileButton.create([options])\n\nA `file-button` can be initiated by invoking the `.create()` method. For example.\n\n```\nvar filebutton = require('file-button');\n\nfilebutton.create();\n```\n\nThe `file-button` instance is also an Event-Emitter using [component-emitter](https://github.com/component/emitter).\n\noptions : {Object}\n\n- multiple: {Boolean}, default to true\n- accept: {String}, default to null\n- fieldName: {String}, default to 'ajaxfile'\n\n### Event: 'fileinput'\n\nEmitted each time the file input value is changed. The `fileinput` element will be removed from the DOM Tree and emitted to the listener.\n\n### Event: 'destroyed'\n\nEmitted after the instance is destroyed.\n\n### filebutton.mount({HtmlElement})\n\nMount the view on an element. For example, a bootstrap button \n\n```\n\u003ca class=\"btn btn-lg btn-primary\"\u003eUpload\u003c/a\u003e\n```\n\n### filebutton.enable()\n\nEnable the file input button.\n\n### filebutton.disable()\n\nDisable the file input button.\n\n### filebutton.destroy()\n\nDestroy the file input button. A `destroyed` event will be emitted.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbenpptung%2Ffile-button","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbenpptung%2Ffile-button","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbenpptung%2Ffile-button/lists"}