{"id":13636709,"url":"https://github.com/jamesmarlowe/lua-resty-s3","last_synced_at":"2025-04-09T11:31:32.647Z","repository":{"id":146528846,"uuid":"21640061","full_name":"jamesmarlowe/lua-resty-s3","owner":"jamesmarlowe","description":"Lua driver for uploading content to amazon s3","archived":false,"fork":false,"pushed_at":"2015-04-22T18:37:59.000Z","size":302,"stargazers_count":39,"open_issues_count":2,"forks_count":8,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-24T05:13:32.253Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Lua","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/jamesmarlowe.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":"2014-07-09T05:03:20.000Z","updated_at":"2024-05-06T03:33:02.000Z","dependencies_parsed_at":"2023-03-28T20:31:05.712Z","dependency_job_id":null,"html_url":"https://github.com/jamesmarlowe/lua-resty-s3","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/jamesmarlowe%2Flua-resty-s3","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamesmarlowe%2Flua-resty-s3/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamesmarlowe%2Flua-resty-s3/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamesmarlowe%2Flua-resty-s3/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jamesmarlowe","download_url":"https://codeload.github.com/jamesmarlowe/lua-resty-s3/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248031441,"owners_count":21036396,"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-08-02T00:01:04.342Z","updated_at":"2025-04-09T11:31:32.105Z","avatar_url":"https://github.com/jamesmarlowe.png","language":"Lua","readme":"Name\n====\n\nlua-resty-s3 - upload content to amazon s3 with openresty\n\nTable of Contents\n=================\n\n* [Name](#name)\n* [Status](#status)\n* [Description](#description)\n* [Synopsis](#synopsis)\n* [Methods](#methods)\n    * [new](#new)\n    * [generate_auth_headers](#generate_auth_headers)\n    * [try_upload](#try_upload)\n    * [upload_url](#upload_url)\n    * [extract_urls](#extract_urls)\n    * [upload_content](#upload_content)\n* [Limitations](#limitations)\n* [Installation](#installation)\n* [TODO](#todo)\n* [Author](#author)\n* [Copyright and License](#copyright-and-license)\n* [See Also](#see-also)\n\nStatus\n======\n\nThis library is still under early development and considered experimental.\n\nDescription\n===========\n\nThis Lua library is a s3 uploading utility for the ngx_lua nginx module:\n\nSynopsis\n========\n\n```\n    lua_package_path \"/path/to/lua-resty-s3/lib/?.lua;;\";\n    \n    server {\n        location /test {\n            content_by_lua '\n                local s3 = require \"resty.s3\"\n                local s3, err = s3:new(\"aws-id\", \"aws-key\")\n                \n                final_url, err = s3:upload_url(\"http://lorempixel.com/400/200/\", \"examplebucket\", \"lorempixel400x200\")`\n            ';\n        }\n        \n        include conf/*.urls;\n    }\n```\n\n[Back to TOC](#table-of-contents)\n\nMethods\n=======\n\nAll of the commands return either something that evaluates to true on success, or `nil` and an error message on failure.\n\nnew\n---\n`syntax: s3, err = s3:new(id, key)`\n\nCreates an uploading object. In case of failures, returns `nil` and a string describing the error.\n\n[Back to TOC](#table-of-contents)\n\ngenerate_auth_headers\n---------------------\n`syntax: s3, err = s3:generate_auth_headers(content_type, destination)`\n\n`syntax: s3, err = s3:generate_auth_headers(\"binary/octet-stream\", \"/examplebucket/lorempixel400x200\")`\n\nCreates the headers needed for authentication with amazon. In case of failures, returns `nil` and a string describing the error.\n\n[Back to TOC](#table-of-contents)\n\ntry_upload\n----------\n`syntax: s3, err = s3:try_upload(content, destination, content_type, headers)`\n\n`syntax: s3, err = s3:try_upload([[\u003ch1\u003eHello\u003c/h1\u003e]], \"/examplebucket/hello\", \"text/html\", headers)`\n\nAttempts to upload content to s3. In case of failures, returns `nil` and a string describing the error.\n\n[Back to TOC](#table-of-contents)\n\nupload_url\n----------\n`syntax: final_url, err = s3:upload_url(file_url, bucket, object_name, check_for_existance, add_to_existance)`\n\n`syntax: final_url, err = s3:upload_url(\"http://lorempixel.com/400/200/\", \"/examplebucket/\", \"lorempixel400x200\")`\n\nAttempts to upload content to s3 from the url set by file_url and the id/key set with new(). If object_name is supplied then that will be the name of the new file, otherwise it will hash the file_url to create a unique key for it.\n\nCallbacks for checking something before uploading [again], and after uploading can be supplied in check_for_existance and add_to_existance. Each will be called with the object_name or a hash.\n\n```\nlocal uploaded_content = ngx.shared.uploaded_content\n\ncheck = function (name)\n  ok, err = uploaded_content:get(name)\n  if ok then return true end\nend\n\nadd = function (name)\n  ok, err = uploaded_content:add(name)\n  return true\nend\n\nfinal_url, err = s3:upload_url(\"http://lorempixel.com/400/200/\", \"/examplebucket/\", \"lorempixel400x200\", check, add)\n```\n\nIn case of success, returns the new url. In case of errors, returns `nil` with a string describing the error.\n\n[Back to TOC](#table-of-contents)\n\nextract_urls\n------------\n`syntax: s3, err = s3:extract_urls(file_content, bucket)`\n\n`syntax: s3, err = s3:extract_urls([[\u003cahref=\"www.google.com\"\u003e\u003cimg src=\"http://lorempixel.com/output/city-q-g-640-480-4.jpg\" /\u003e\u003c/a\u003e]], \"/examplebucket/\")`\n\nAttempts to find and upload urls from within source. In case of failures, returns `nil` and a string describing the error.\n\n[Back to TOC](#table-of-contents)\n\nupload_content\n--------------\n`syntax: s3, err = s3:upload_content(file_content, bucket, object_name, check_for_existance, add_to_existance)`\n\n`syntax: s3, err = s3:upload_content([[\u003cahref=\"www.google.com\"\u003e\u003cimg src=\"http://lorempixel.com/output/city-q-g-640-480-4.jpg\" /\u003e\u003c/a\u003e]], \"/examplebucket/\", \"city.jpg\")`\n\nAttempts to upload content to s3 (handles all auth automatically). In case of failures, returns `nil` and a string describing the error.\n\n[Back to TOC](#table-of-contents)\n\nLimitations\n===========\n\n\n\n[Back to TOC](#table-of-contents)\n\nInstallation\n============\nYou can install it with luarocks `luarocks install lua-resty-s3`\n\nOtherwise you need to configure the lua_package_path directive to add the path of your lua-nginx-loggin source to ngx_lua's LUA_PATH search path, as in\n\n```nginx\n    # nginx.conf\n    http {\n        lua_package_path \"/path/to/lua-resty-s3/lib/?.lua;;\";\n        ...\n    }\n```\n\nThis package also requires the luasocket and xxhash packages to be installed http://w3.impa.br/~diego/software/luasocket/ , https://github.com/mah0x211/lua-xxhash\n```\nluarocks install luasocket\n```\n\nEnsure that the system account running your Nginx ''worker'' proceses have\nenough permission to read the `.lua` file.\n\n[Back to TOC](#table-of-contents)\n\nTODO\n====\n\n\n\n[Back to TOC](#table-of-contents)\n\nAuthor\n======\n\nJames Marlowe \"jamesmarlowe\" \u003cjameskmarlowe@gmail.com\u003e, Lumate LLC.\n\n[Back to TOC](#table-of-contents)\n\nCopyright and License\n=====================\n\nThis module is licensed under the BSD license.\n\nCopyright (C) 2012-2014, by James Marlowe (jamesmarlowe) \u003cjameskmarlowe@gmail.com\u003e, Lumate LLC.\n\nAll rights reserved.\n\nRedistribution and use in source and binary forms, with or without\nmodification, are permitted provided that the following conditions are met:\n\n* Redistributions of source code must retain the above copyright notice, this\n  list of conditions and the following disclaimer.\n\n* Redistributions in binary form must reproduce the above copyright notice,\n  this list of conditions and the following disclaimer in the documentation\n  and/or other materials provided with the distribution.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"\nAND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\nIMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\nDISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE\nFOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\nDAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\nSERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\nCAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,\nOR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\nOF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n\n[Back to TOC](#table-of-contents)\n\nSee Also\n========\n* the ngx_lua module: http://wiki.nginx.org/HttpLuaModule\n* the [lua-resty-hmac](https://github.com/jamesmarlowe/lua-resty-hmac) library\n\n[Back to TOC](#table-of-contents)\n","funding_links":[],"categories":["Libraries","Lua"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjamesmarlowe%2Flua-resty-s3","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjamesmarlowe%2Flua-resty-s3","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjamesmarlowe%2Flua-resty-s3/lists"}