{"id":15672539,"url":"https://github.com/phstc/node-upload-progress","last_synced_at":"2025-05-06T22:09:40.711Z","repository":{"id":3698578,"uuid":"4769484","full_name":"phstc/node-upload-progress","owner":"phstc","description":"It's a Node.js module to handle upload and upload-progress","archived":false,"fork":false,"pushed_at":"2023-12-28T17:22:03.000Z","size":44,"stargazers_count":16,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-06T22:09:34.800Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"CoffeeScript","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/phstc.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2012-06-24T03:04:01.000Z","updated_at":"2023-12-28T17:21:08.000Z","dependencies_parsed_at":"2024-10-23T10:37:57.583Z","dependency_job_id":"6c181707-111f-4962-9cf3-5893570b64a9","html_url":"https://github.com/phstc/node-upload-progress","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phstc%2Fnode-upload-progress","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phstc%2Fnode-upload-progress/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phstc%2Fnode-upload-progress/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phstc%2Fnode-upload-progress/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phstc","download_url":"https://codeload.github.com/phstc/node-upload-progress/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252776599,"owners_count":21802469,"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":[],"created_at":"2024-10-03T15:28:06.711Z","updated_at":"2025-05-06T22:09:40.347Z","avatar_url":"https://github.com/phstc.png","language":"CoffeeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"It's a Node.js module to handle upload and upload-progress.\n\n[![Build Status](https://secure.travis-ci.org/phstc/node-upload-progress.png)](http://travis-ci.org/phstc/node-upload-progress)\n\n##Instal\n\n    $ npm install node-upload-progress\n\nor\n\n    # package.json\n    # ...\n    \"dependencies\": {\n      \"node-upload-progress\": \"latest\"\n    }\n    # ...\n\n    $ npm install\n\n##Usage\n\n###Simple\n\n    var app = require('http');\n    var uploadProgress = require('node-upload-progress');\n\n    uploadHandler = new uploadProgress.UploadHandler;\n\nThe ```uploadHandler.uploadDir``` is the path where the files will be saved. Without this configuration the files will be saved in a path based on ```process.env.TMP```.\n\n    uploadHandler.configure(function() {\n      this.uploadDir = __dirname + '/uploads';\n    });\n\n    app.createServer(function(req, res) {\n      if (req.url === '/upload') {\n        uploadHandler.upload(req, res);\n        return;\n      }\n      # ...\n    }\n\n####Custom response body\n\nConfiguring the ```uploadHandler.onEnd = customOnEndHandler```, you can write your own response body.\n\n    # ...\n    uploadHandler.configure(function() {\n      this.uploadDir = \"\" + __dirname + \"/uploads\";\n      this.onEnd = customOnEndHandler;\n    });\n\n    function customOnEndHandler(req, res){\n      res.writeHead 200, {'Content-Type': 'text/plain'}\n      res.end('Upload received');\n    }\n\n    app.createServer(function(req, res) {\n      if (req.url === '/upload') {\n        uploadHandler.upload(req, res);\n        return;\n      }\n      # ...\n    }\n\nSee a full example at [examples/simple](https://github.com/phstc/node-upload-progress/tree/master/examples/simple).\n\n##Progress\n\nIf you want to use an upload progress similar to [Nginx Upload Progress Module](http://wiki.nginx.org/HttpUploadProgressModule), you can easily do it using the progress handler.\n\n    # ...\n    app.createServer(function(req, res) {\n      if (req.url.match(/\\/upload\\?X\\-Progress\\-ID=.+/)) {\n        uploadHandler.upload(req, res);\n        return;\n      } else if (req.url.match(/\\/progress\\?X\\-Progress\\-ID=.+/)) {\n        uploadHandler.progress(req, res);\n        return;\n      }\n      # ...\n    }\n\n###The view\n\n#### The Javascript\n\n    \u003cscript\u003e\n    \t$(function(){\n    \t\t$('#form_upload').submit(function(){\n    \t\t\tvar xProgressID = guidGenerator();\n    \t\t\t$(this).attr('action', '/upload?X-Progress-ID=' + xProgressID);\n    \t\t\tvar uploadIntervalID = setInterval(function(){\n    \t\t\t\t$.get('/progress?X-Progress-ID=' + xProgressID, function(data){\n    \t\t\t\t\tif(data.status === 'done'){\n    \t\t\t\t\t\tclearInterval(uploadIntervalID);\n    \t\t\t\t\t}\n    \t\t\t\t\tupdateViewUploadStatus(data);\n    \t\t\t\t}).error(function(){clearInterval(uploadIntervalID)});\n    \t\t\t}, 250);\n    \t\t\treturn true;\n    \t\t});\n    \t\tfunction updateViewUploadStatus(data){\n    \t\t\t# ...\n    \t\t}\n    \t\t// http://stackoverflow.com/a/105074/464685\n    \t\tfunction guidGenerator() {\n    \t\t\t# ...\n    \t\t}\n    \t});\n    \u003c/script\u003e\n\n####The HTML\n\n    # ...\n    \u003cform action=\"/upload?X-Progress-ID=1\" enctype=\"multipart/form-data\" method=\"post\" id=\"form_upload\" target=\"iframe_upload\"\u003e\n    \t\u003cp\u003e\n    \t\t\u003clabel\u003eFile\u003c/label\u003e\u003cbr/\u003e\n    \t\t\u003cinput type=\"file\" name=\"upload\" id=\"upload\"\u003e\u003cbr\u003e\n    \t\u003c/p\u003e\n    \t\u003cp\u003e\n    \t\t\u003cinput type=\"submit\" value=\"Upload\"\u003e\n    \t\u003c/p\u003e\n    \u003c/form\u003e\n    \u003ciframe id=\"iframe_upload\" name=\"iframe_upload\"\u003e\u003c/iframe\u003e\n    # ...\n\nSee a full example at [examples/progress](https://github.com/phstc/node-upload-progress/tree/master/examples/progress).\n\n###The possible status\n\nThe upload request hasn't been registered yet or is unknown:\n\n    HTTP 404 Not Found\n\nThe upload request has ended:\n\n    {\"bytesReceived\":N,\n     \"bytesExpected\":N,\n     \"percent\":100,\n     \"status\":\"done\",\n     \"fileName\":\"filename.txt\",\n     \"filePath\":\"uploadDir/filename.txt\"}\n\nThe upload request is in progress:\n\n    {\"bytesReceived\":N,\"bytesExpected\":N,\"percent\":N,\"status\":\"uploading\"}\n\n##Running it\n\n###Simple example\n\n    $ make simple\n\nThen\n\n    open http://localhost:8080\n\n###Progress example\n\n    $ make progress\n\nThen\n\n    open http://localhost:8080\n\n###Test suite\n\n    $ make test\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphstc%2Fnode-upload-progress","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphstc%2Fnode-upload-progress","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphstc%2Fnode-upload-progress/lists"}