{"id":18614003,"url":"https://github.com/midudev/s3-folder-upload","last_synced_at":"2025-04-10T23:32:12.822Z","repository":{"id":53750105,"uuid":"66553041","full_name":"midudev/s3-folder-upload","owner":"midudev","description":"Upload easily a folder to Amazon Simple Storage Service (S3)","archived":true,"fork":false,"pushed_at":"2021-03-16T08:47:10.000Z","size":82,"stargazers_count":44,"open_issues_count":7,"forks_count":26,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-10T09:09:25.663Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/midudev.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":"2016-08-25T11:42:48.000Z","updated_at":"2025-01-02T16:28:51.000Z","dependencies_parsed_at":"2022-09-02T03:21:39.661Z","dependency_job_id":null,"html_url":"https://github.com/midudev/s3-folder-upload","commit_stats":null,"previous_names":["miduga/s3-folder-upload"],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/midudev%2Fs3-folder-upload","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/midudev%2Fs3-folder-upload/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/midudev%2Fs3-folder-upload/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/midudev%2Fs3-folder-upload/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/midudev","download_url":"https://codeload.github.com/midudev/s3-folder-upload/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248316507,"owners_count":21083456,"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-11-07T03:24:41.657Z","updated_at":"2025-04-10T23:32:11.822Z","avatar_url":"https://github.com/midudev.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# s3 folder upload\n\n[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)\n[![npm version](https://badge.fury.io/js/s3-folder-upload.svg)](https://badge.fury.io/js/s3-folder-upload)\n[![npm](https://img.shields.io/npm/dm/s3-folder-upload.svg?maxAge=2592000)]()\n\nA little script to upload statics to a S3 bucket by using the official Amazon SDK.\n\n## AWS Credentials\n\nIn order to use this module, you'll need to have AWS Credentials. You can load them, two ways:\n\n* By passing directly to the method as second parameter.\n* By having a ENV variable with the path to a file with the credentials.\n  The ENV variable is `AWS_CREDENTIALS_PATH` and it should have `accessKeyId`, `secretAccessKey`, `region` and `bucket`.\n\n## Install\n\n```bash\nnpm install s3-folder-upload -D\n```\n\nIn case you want to use the CLI, you can install it globally:\n\n```bash\nnpx s3-folder-upload\n```\n\n## Require\n\n```javascript\nconst s3FolderUpload = require('s3-folder-upload')\n// or the ES6 way\n// import s3FolderUpload from 's3-folder-upload'\n\nconst directoryName = 'statics'\n// I strongly recommend to save your credentials on a JSON or ENV variables, or command line args\nconst credentials = {\n  \"accessKeyId\": \"\u003cYour Access Key Id\u003e\",\n  \"secretAccessKey\": \"\u003cYour Secret Access Key\u003e\",\n  \"region\": \"\u003cYour Aimed Region\u003e\",\n  \"bucket\": \"\u003cYour Bucket Name\u003e\"\n}\n\n// optional options to be passed as parameter to the method\nconst options = {\n  useFoldersForFileTypes: false,\n  useIAMRoleCredentials: false\n}\n\n// optional cloudfront invalidation rule\nconst invalidation = {\n  awsDistributionId: \"\u003cYour CloudFront Distribution Id\u003e\",\n  awsInvalidationPath: \"\u003cThe Path to Invalidate\u003e\"\n}\n\ns3FolderUpload(directoryName, credentials, options, invalidation)\n```\n\n## Options\n\n- `useFoldersForFileTypes` (default: `true`): Upload files to a specific subdirectory according to its file type.\n- `useIAMRoleCredentials` (default: `false`): It will ignore all the credentials passed via parameters or environment variables in order to use the instance IAM credentials profile.\n- `uploadFolder` (default: `undefined`): If it's specified, the statics will be uploaded to the folder, so if you upload `static.js` to `https://statics.s3.eu-west-1.amazonaws.com` with a `uploadFolder` with value `my-statics` the file will be uploaded to: `https://statics.s3.eu-west-1.amazonaws.com/my-statics/static.js`.\n- `ACL` (default: `public-read`): It defines which AWS accounts or groups are granted access and the type of access.\n- `CacheControl` (default: `public, max-age=31536000`): HTTP header holds directives (instructions) for caching in both requests and responses.\n- `Expires` (default: `31536000`): Header contains the date/time after which the response is considered stale. If there is a Cache-Control header with the max-age or s-maxage directive in the response, the Expires header is ignored.\n\nIf you use programatically the library, you could overwrite the `ACL`, `CacheControl` and `Expires` values to file level.\n\n```javascript\nconst options = {\n  useFoldersForFileTypes: false,\n  useIAMRoleCredentials: false,\n}\n\nconst filesOptions = {\n  'index.html': {\n    CacheControl: 'public, max-age=300',\n    Expires: new Date(\"Fri, 01 Jan 1971 00:00:00 GMT\")\n  }\n}\n\ns3FolderUpload(directoryName, credentials, options, filesOptions)\n```\n\n## CLI\n\n```bash\ns3-folder-upload \u003cfolder\u003e\n\nExample:\ns3-folder-upload statics\n```\n\n**For the AWS Credentials**\n\n* you can define a ENV variable called `AWS_CREDENTIALS_PATH` with the path of the file with the needed info.\n* you can pass the needed info via command line parameters:\n    ```bash\n    s3-folder-upload \u003cfolder\u003e --accessKeyId=\u003cyour access key id\u003e --bucket=\u003cdestination bucket\u003e --region=\u003cregion\u003e --secretAccessKey=\u003cyour secret access key\u003e\n    ```\n* you can use `useIAMRoleCredentials` option in order to rely on IAM Profile instance instead any passed by variables and environment\n\n**For Options**\n\n* you can pass the needed info via command line parameters:\n    ```bash\n    s3-folder-upload \u003cfolder\u003e \u003ccredentials parameters\u003e --useFoldersForFileTypes=false\n    ```\n\n**For CloudFront invalidation**\n\n* you can pass the needed info via command line parameters, the invalidation needs both parameters:\n    ```bash\n    s3-folder-upload \u003cfolder\u003e \u003ccredentials parameters\u003e --awsDistributionId=\u003cdistributionId\u003e --awsInvalidationPath=\"/js/*\"\n\n### Environment Variables\n\n`S3_FOLDER_UPLOAD_LOG`: You could specify the level of logging for the library.\n* `none`: No logging output\n* `only_errors`: Only errors are logged\n* `all` (default): Errors, progress and useful messages are logged.\n\nExample of use:\n```\nS3_FOLDER_UPLOAD_LOG=only_errors s3-folder-upload \u003cfolder\u003e\n```\n\nIf you use the library programatically, this ENVIRONEMNT_VARIABLE will be read as well. For example:\n\n```\nS3_FOLDER_UPLOAD_LOG=only_errors node upload-script.js\n```\n\n## Wish list\n\n- [x] Upload a entire folder to S3 instead file\n- [x] Async upload of files to improve time\n- [x] Detect automatically the content type of (limited support)\n- [x] Return the list of files uploaded with the final URL\n- [x] Better support for parameters with the CLI\n- [ ] Improve content type function in order to get more and better types of files\n- [ ] Avoid to re-upload files if they didn't change\n- [ ] Check if cache is blocking updates of statics on website.\n- [ ] Map uploaded paths to create a default invalidation paths rule in CloudFront.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmidudev%2Fs3-folder-upload","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmidudev%2Fs3-folder-upload","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmidudev%2Fs3-folder-upload/lists"}