- Initiate the node project npm init
- Create app.js
- Write console logs and run
๐
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Generates a presigned URL of the file if it is successfully uploaded to S3 | |
/// </summary> | |
/// <param name="file">File to be Uploaded</param> | |
/// <returns></returns> | |
public async Task<string> GetS3ObjectPresignedUrl(IFormFile file) | |
{ | |
try | |
{ | |
var key = Path.GetRandomFileName() + Guid.NewGuid().ToString() + Path.GetExtension(file.FileName).ToLowerInvariant(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace CodePanthers.AWS.S3.UploadService.Controllers | |
{ | |
[Route("Upload")] | |
public class UploadController : Controller | |
{ | |
private readonly IFileUploadService _fileUploadService; | |
public UploadController(IFileUploadService fileUploadService) | |
{ | |
_fileUploadService = fileUploadService; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"Version": "2012-10-17", | |
"Statement": [ | |
{ | |
"Sid": "VisualEditor0", | |
"Effect": "Allow", | |
"Action": [ | |
"sns:Publish", | |
"sns:Subscribe" | |
], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Threading.Tasks; | |
namespace CodePanthers.AWS.S3.UploadService.Services | |
{ | |
public interface INotificationService | |
{ | |
Task SendUploadNotification(string topic, string message); | |
Task SendUploadNotification(string message); | |
Task RegisterSubscirption(string email); | |
Task RegisterSubscirption(string topic, string email); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Amazon.SimpleNotificationService; | |
using Amazon.SimpleNotificationService.Model; | |
using Microsoft.Extensions.Configuration; | |
using System; | |
using System.Threading.Tasks; | |
namespace CodePanthers.AWS.S3.UploadService.Services | |
{ | |
public class NotificationService : INotificationService | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public async Task<string> GetS3ObjectPresignedUrl(IFormFile file) | |
{ | |
try | |
{ | |
var key = Path.GetRandomFileName() + Guid.NewGuid().ToString() + Path.GetExtension(file.FileName).ToLowerInvariant(); | |
if (await UploadFileToS3(file, key)) | |
{ | |
var getUrlRequest = new GetPreSignedUrlRequest | |
{ | |
BucketName = BucketName, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[HttpPost("register")] | |
public async Task<IActionResult> RegisterEmailSubscription([FromBody] string email) | |
{ | |
if (string.IsNullOrEmpty(email)) | |
{ | |
return BadRequest(new { status = "Failed", message = "Enter a valid Email Address" }); | |
} | |
else | |
{ | |
await _notificationService.RegisterSubscirption(email); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Logs | |
logs | |
*.log | |
npm-debug.log* | |
yarn-debug.log* | |
yarn-error.log* | |
lerna-debug.log* | |
.pnpm-debug.log* | |
# Diagnostic reports (https://nodejs.org/api/report.html) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require("express"); | |
const app = express(); | |
const PORT = process.env.PORT || 80; | |
app.get("/",(req,res)=> { | |
res.send("Hello From Code Panthers"); | |
res.end(); | |
}) | |
app.listen(PORT,() => { |
OlderNewer