{"_id":"@csn-storage/aws-s3","_rev":"1-6a457e5209326a89439c0d64d9e69b9d","name":"@csn-storage/aws-s3","dist-tags":{"latest":"1.1.0"},"versions":{"1.0.0":{"name":"@csn-storage/aws-s3","version":"1.0.0","keywords":["aws","s3","nodejs","aws s3","bucket","file management","storage","storage management","csn","codesmith","ninja"],"author":{"name":"Divyang patel","email":"divyangpatel54@gmail.com"},"license":"MIT","_id":"@csn-storage/aws-s3@1.0.0","maintainers":[{"name":"codesmith-ninja","email":"divyangpatel54@gmail.com"}],"homepage":"https://github.com/codesmithNinja/storage-management#readme","bugs":{"url":"https://github.com/codesmithNinja/storage-management/issues"},"dist":{"shasum":"0b2428aa3f18f2d9da8bbcd6659d0992816f0658","tarball":"https://registry.npmjs.org/@csn-storage/aws-s3/-/aws-s3-1.0.0.tgz","fileCount":4,"integrity":"sha512-JeocLM++viujLB2DkeyL3Avx9PPrxs38ijBCtb8y5/fhJ30aNGRqntTfrkMZ1L43mm1aqx1RmDW0I0cMbFGJzw==","signatures":[{"sig":"MEQCIHGCeDjzKOR7f5dxrtpAKMsZUJJ0/6vTH77kKOthJWHDAiB6GeYjqwkhLFZVzjdtMWFUoyH/sy+rN39lms/mpu/nPQ==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":7625},"main":"index.js","gitHead":"1867c6943b7cb1b8ef4f0884aa18f09db0e69f44","scripts":{"build":""},"_npmUser":{"name":"codesmith-ninja","email":"divyangpatel54@gmail.com"},"repository":{"url":"git+https://github.com/codesmithNinja/storage-management.git","type":"git"},"_npmVersion":"10.2.4","description":"A Node.js package for managing files in an AWS S3 bucket. This package provides a simple and efficient way to upload, download, list, and delete files in S3 bucket also gives feature for generating pre-signed URLs. Ideal for applications that require robu","directories":{},"_nodeVersion":"20.11.1","dependencies":{"mime-types":"^2.1.35","@aws-sdk/client-s3":"^3.722.0","@aws-sdk/s3-request-presigner":"^3.722.0"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/aws-s3_1.0.0_1736015029370_0.890255643437188","host":"s3://npm-registry-packages-npm-production"}},"1.1.0":{"name":"@csn-storage/aws-s3","version":"1.1.0","description":"A Node.js package for managing files in an AWS S3 bucket. This package provides a simple and efficient way to upload, download, list, and delete files in S3 bucket also gives feature for generating pre-signed URLs. Ideal for applications that require robu","main":"index.js","keywords":["aws","s3","nodejs","aws s3","bucket","file management","storage","storage management","csn","codesmith","ninja"],"scripts":{"build":""},"repository":{"type":"git","url":"git+https://github.com/codesmithNinja/csn-storage-aws-s3.git"},"author":{"name":"Divyang patel","email":"divyangpatel54@gmail.com"},"license":"MIT","bugs":{"url":"https://github.com/codesmithNinja/csn-storage-aws-s3/issues"},"homepage":"https://github.com/codesmithNinja/csn-storage-aws-s3#readme","dependencies":{"@aws-sdk/client-s3":"^3.722.0","@aws-sdk/s3-request-presigner":"^3.722.0","mime-types":"^2.1.35"},"_id":"@csn-storage/aws-s3@1.1.0","gitHead":"13b2b0187acbf083c740d2da8a9649dbcc0ff909","_nodeVersion":"20.11.1","_npmVersion":"10.2.4","dist":{"integrity":"sha512-HHW/5dXtVAJ+h+tw1asm/HeCwqsn0+fkZQFnRsci7YdiswhceNBL7tIrsRW+wDK9RKYo1ySjTTgbZaCF+xesFA==","shasum":"bb7c971a1bcf18bc972c825243afec87b602645e","tarball":"https://registry.npmjs.org/@csn-storage/aws-s3/-/aws-s3-1.1.0.tgz","fileCount":4,"unpackedSize":15914,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDKkgmoPzbAm6xFjJsqKLLIoehaGNU2GbTi+4uS/epOMAIhAO0OMF1tdqSw74VBhKuEZ1aNL60ZGszU2OKCJUW4ero3"}]},"_npmUser":{"name":"codesmith-ninja","email":"divyangpatel54@gmail.com"},"directories":{},"maintainers":[{"name":"codesmith-ninja","email":"divyangpatel54@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/aws-s3_1.1.0_1736156080208_0.5581490907472193"},"_hasShrinkwrap":false}},"time":{"created":"2025-01-04T18:23:49.308Z","modified":"2025-01-06T09:34:40.553Z","1.0.0":"2025-01-04T18:23:49.541Z","1.1.0":"2025-01-06T09:34:40.356Z"},"bugs":{"url":"https://github.com/codesmithNinja/csn-storage-aws-s3/issues"},"author":{"name":"Divyang patel","email":"divyangpatel54@gmail.com"},"license":"MIT","homepage":"https://github.com/codesmithNinja/csn-storage-aws-s3#readme","keywords":["aws","s3","nodejs","aws s3","bucket","file management","storage","storage management","csn","codesmith","ninja"],"repository":{"type":"git","url":"git+https://github.com/codesmithNinja/csn-storage-aws-s3.git"},"description":"A Node.js package for managing files in an AWS S3 bucket. This package provides a simple and efficient way to upload, download, list, and delete files in S3 bucket also gives feature for generating pre-signed URLs. Ideal for applications that require robu","maintainers":[{"name":"codesmith-ninja","email":"divyangpatel54@gmail.com"}],"readme":"# @csn-storage/aws-s3\r\n\r\nA Node.js package for managing files in an AWS S3 bucket. This package provides a simple and efficient way to upload, download, list, and delete files in an S3 bucket. It also includes features for generating pre-signed URLs. Ideal for applications that require robust file management capabilities with AWS S3.\r\n\r\n## Features\r\n\r\n- **Upload files** to an S3 bucket.\r\n- **Download files** from an S3 bucket.\r\n- **Delete files** from an S3 bucket.\r\n- **Delete directories** (all files within a directory) from an S3 bucket.\r\n- **Generate pre-signed URLs** for secure, time-limited access to files.\r\n- **Streamable URLs** for inline content display (e.g., images, videos).\r\n\r\n## Installation\r\n\r\nTo install the package, use npm:\r\n\r\n    npm install @csn-storage/aws-s3\r\n\r\n## Usage\r\n\r\n### 1\\. Import the Package\r\n\r\n    const { createClient, getPublicURL, uploadFile, deleteFile, deleteDir } = require('@csn-storage/aws-s3');\r\n\r\n### 2\\. Create an S3 Client\r\n\r\nBefore performing any operations, you need to create an S3 client instance using your AWS credentials.\r\n\r\n    const s3Client = createClient('your-region', 'your-access-key-id', 'your-secret-access-key');\r\n\r\n- **Parameters:**\r\n  - `region` (string): AWS region (e.g., `us-east-1`).\r\n  - `accessKeyId` (string): AWS access key ID.\r\n  - `secretAccessKey` (string): AWS secret access key.\r\n- **Returns:** An instance of `S3Client`.\r\n\r\n### 3\\. Upload a File\r\n\r\nUpload a file to an S3 bucket.\r\n\r\nThe `uploadFile` function allows you to upload a file to an S3 bucket. You can specify the file name, including the folder name, to upload the file to a specific location in the bucket.\r\n\r\n    const imageBuffer = fs.readFileSync('path/to/image.jpg');\r\n    await uploadFile(s3Client, 'your-bucket-name', 'images/image.jpg', imageBuffer);\r\n\r\n- **Parameters:**\r\n  - `s3Client` (S3Client): An instance of `S3Client`.\r\n  - `bucketName` (string): Name of the S3 bucket.\r\n  - `fileName` (string): Name of the file.\r\n  - `file` (Buffer | Object): A Buffer or a file object with a `buffer` property.\r\n- **Returns:** A promise that resolves when the file is uploaded.\r\n\r\n#### Conditions\r\n\r\n- The `file` parameter can be either a `Buffer` or a file object with a `buffer` property.\r\n- The `fileName` parameter should include the folder name if you want to upload the file to a specific folder.\r\n- The `bucketName` parameter should be the name of the S3 bucket where you want to upload the file.\r\n\r\n#### Example: Uploading an Image\r\n\r\nHere’s an example of uploading an image file (e.g., `image.jpg`) to a specific folder in the S3 bucket:\r\n\r\n    // Example: Uploading an image file\r\n        const fs = require('fs');\r\n\r\n        // Read the image file into a Buffer\r\n        const imageBuffer = fs.readFileSync('path/to/image.jpg');\r\n\r\n        // Upload the image to the S3 bucket\r\n        await uploadFile(s3Client, 'your-bucket-name', 'images/image.jpg', imageBuffer);\r\n\r\n**Explanation:**\r\n\r\n- The `fs.readFileSync` method reads the image file into a `Buffer`.\r\n- The `uploadFile` function uploads the image to the S3 bucket under the folder `images/` with the file name `image.jpg`.\r\n\r\n#### Example: Uploading an Image with a File Object\r\n\r\nHere’s an example of uploading an image file (e.g., `image.jpg`) to a specific folder in the S3 bucket using a file object:\r\n\r\n    // Example: Uploading an image file with a file object\r\n        const fs = require('fs');\r\n\r\n        // Read the image file into a Buffer\r\n        const imageBuffer = fs.readFileSync('path/to/image.jpg');\r\n\r\n        // Create a file object with the buffer property\r\n        const imageFile = { buffer: imageBuffer };\r\n\r\n        // Upload the image to the S3 bucket\r\n        await uploadFile(s3Client, 'your-bucket-name', 'images/image.jpg', imageFile);\r\n\r\n**Explanation:**\r\n\r\n- The `fs.readFileSync` method reads the image file into a `Buffer`.\r\n- The file object is created with the `buffer` property set to the image buffer.\r\n- The `uploadFile` function uploads the image to the S3 bucket under the folder `images/` with the file name `image.jpg`.\r\n\r\n### 4\\. Generate a Pre-Signed URL\r\n\r\nGenerate a pre-signed URL for a file in the S3 bucket.\r\n\r\nThe `getPublicURL` function allows you to generate a pre-signed URL for a file in the S3 bucket. This URL provides secure, time-limited access to the file.\r\n\r\n    const imageUrl = await getPublicURL(s3Client, 'your-bucket-name', 'images/image.jpg', 10, true);\r\n\r\n- **Parameters:**\r\n  - `s3Client` (S3Client): An instance of `S3Client`.\r\n  - `bucketName` (string): Name of the S3 bucket.\r\n  - `fileName` (string): Name of the file.\r\n  - `expiresInMinutes` (number, optional): Time in minutes until the URL expires. Default is `10`.\r\n  - `isStreamable` (boolean, optional): If `true`, the URL will be streamable (e.g., for inline content). Default is `false`.\r\n- **Returns:** A pre-signed URL (string).\r\n\r\n#### Conditions\r\n\r\n- The `fileName` parameter should include the folder name if the file is located in a specific folder.\r\n- The `expiresInMinutes` parameter specifies the time (in minutes) until the URL expires. The default is 10 minutes.\r\n- The `isStreamable` parameter, if set to `true`, generates a URL that can be used to stream the file (e.g., for inline content like images or videos).\r\n\r\n#### Example: Generating a Pre-Signed URL for an Image\r\n\r\nHere’s an example of generating a pre-signed URL for an image file (e.g., `image.jpg`) in the S3 bucket:\r\n\r\n    // Generate a pre-signed URL for an image file\r\n        const imageUrl = await getPublicURL(s3Client, 'your-bucket-name', 'images/image.jpg', 10, true);\r\n        console.log(imageUrl);\r\n\r\n**Explanation:**\r\n\r\n- The `getPublicURL` function generates a pre-signed URL for the file `images/image.jpg` in the S3 bucket.\r\n- The URL expires in 10 minutes (`expiresInMinutes: 10`).\r\n- The `isStreamable: true` parameter ensures the URL can be used to stream the image inline (e.g., in a web page).\r\n\r\n### 5\\. Delete a File\r\n\r\nDelete a file from the S3 bucket.\r\n\r\nThe `deleteFile` function allows you to delete a specific file from the S3 bucket.\r\n\r\n    await deleteFile(s3Client, 'your-bucket-name', 'images/image.jpg');\r\n\r\n- **Parameters:**\r\n  - `s3Client` (S3Client): An instance of `S3Client`.\r\n  - `bucketName` (string): Name of the S3 bucket.\r\n  - `fileName` (string): Name of the file.\r\n- **Returns:** A promise that resolves when the file is deleted.\r\n\r\n#### Conditions\r\n\r\n- The `fileName` parameter should include the folder name if the file is located in a specific folder.\r\n- The `bucketName` parameter should be the name of the S3 bucket where the file is stored.\r\n\r\n#### Example: Deleting an Image File\r\n\r\nHere’s an example of deleting an image file (e.g., `image.jpg`) from the S3 bucket:\r\n\r\n    // Delete an image file from the S3 bucket\r\n        await deleteFile(s3Client, 'your-bucket-name', 'images/image.jpg');\r\n\r\n**Explanation:**\r\n\r\n- The `deleteFile` function deletes the file `images/image.jpg` from the S3 bucket.\r\n- The file is permanently removed from the bucket.\r\n\r\n### 6\\. Delete a Directory\r\n\r\nDelete all files within a directory in the S3 bucket.\r\n\r\nThe `deleteDir` function allows you to delete all files within a specific directory (folder) in the S3 bucket.\r\n\r\n    await deleteDir(s3Client, 'your-bucket-name', 'images');\r\n\r\n- **Parameters:**\r\n  - `s3Client` (S3Client): An instance of `S3Client`.\r\n  - `bucketName` (string): Name of the S3 bucket.\r\n  - `dirName` (string): Name of the directory to delete.\r\n- **Returns:** A promise that resolves when the directory and its contents are deleted.\r\n\r\n#### Conditions\r\n\r\n- The `bucketName` parameter should be the name of the S3 bucket where the directory is located.\r\n- The function recursively deletes all files within the specified directory.\r\n\r\n#### Example: Deleting a Directory\r\n\r\nHere’s an example of deleting all files within the `images/` directory in the S3 bucket:\r\n\r\n    // Delete all files within the 'images/' directory\r\n        await deleteDir(s3Client, 'your-bucket-name', 'images/');\r\n\r\n**Explanation:**\r\n\r\n- The `deleteDir` function deletes all files within the specified directory `images/` in the S3 bucket.\r\n- This operation is recursive, meaning it will remove all files and subdirectories within the specified directory.\r\n\r\n## License\r\n\r\nThis project is licensed under the MIT License. See the [LICENSE](https://github.com/codesmithNinja/csn-storage-aws-s3/blob/main/LICENSE) file for details.\r\n","readmeFilename":"README.md"}