Skip to content

Commit

Permalink
Cloud Storage
Browse files Browse the repository at this point in the history
  • Loading branch information
KonduruKeerthi committed Jul 4, 2024
1 parent af03ff6 commit f255de8
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,10 @@ public IActionResult Index()
}
public async Task<IActionResult> EditDocument()
{
//Your AWS Storage Account bucket name
string bucketName = "your-bucket-name";

//Name of the PowerPoint file you want to load from AWS S3
string key = "PowerPointTemplate.pptx";

try
{
//Retrieve the document from AWS S3
MemoryStream stream = await GetDocumentFromS3(bucketName, key);
MemoryStream stream = await GetDocumentFromS3();

//Set the position to the beginning of the MemoryStream
stream.Position = 0;
Expand All @@ -48,7 +42,7 @@ public async Task<IActionResult> EditDocument()
if (shape.TextBody.Text == "Company History")
shape.TextBody.Text = "Company Profile";

//Saving the PowerPoint document to a MemoryStream
//Saving the PowerPoint file to a MemoryStream
MemoryStream outputStream = new MemoryStream();
pptxDocument.Save(outputStream);

Expand All @@ -70,8 +64,14 @@ public async Task<IActionResult> EditDocument()
/// <param name="bucketName"></param>
/// <param name="key"></param>
/// <returns></returns>
public async Task<MemoryStream> GetDocumentFromS3(string bucketName, string key)
public async Task<MemoryStream> GetDocumentFromS3()
{
//Your AWS Storage Account bucket name
string bucketName = "your-bucket-name";

//Name of the PowerPoint file you want to load from AWS S3
string key = "PowerPointTemplate.pptx";

//Configure AWS credentials and region
var region = Amazon.RegionEndpoint.USEast1;
var credentials = new Amazon.Runtime.BasicAWSCredentials("your-access-key", "your-secret-key");
Expand All @@ -98,7 +98,6 @@ public async Task<MemoryStream> GetDocumentFromS3(string bucketName, string key)
await response.ResponseStream.CopyToAsync(stream);

return stream;

}
}
catch (Exception ex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,14 @@ public async Task<IActionResult> UploadDocument()
stampShape.Fill.FillType = FillType.None;
stampShape.TextBody.AddParagraph("IMN").HorizontalAlignment = HorizontalAlignmentType.Center;

//Saves the PowerPoint document to MemoryStream
//Saves the PowerPoint to MemoryStream
MemoryStream stream = new MemoryStream();
pptxDocument.Save(stream);

//Your AWS Storage Account bucket name
string bucketName = "your-bucket-name";

//Name of the PowerPoint file you want to upload
string key = "CreatePowerPoint.pptx";
pptxDocument.Save(stream);

//Upload the document to AWS S3
await UploadDocumentToS3(bucketName, key, stream);
await UploadDocumentToS3(stream);

return Ok("PowerPoint document uploaded to AWS S3 Storage.");
return Ok("PowerPoint uploaded to AWS S3 Storage.");
}
/// <summary>
/// Upload file to AWS S3 cloud storage
Expand All @@ -94,8 +88,14 @@ public async Task<IActionResult> UploadDocument()
/// <param name="key"></param>
/// <param name="stream"></param>
/// <returns></returns>
public async Task<MemoryStream> UploadDocumentToS3(string bucketName, string key, MemoryStream stream)
public async Task<MemoryStream> UploadDocumentToS3(MemoryStream stream)
{
//Your AWS Storage Account bucket name
string bucketName = "your-bucket-name";

//Name of the PowerPoint file you want to upload
string key = "CreatePowerPoint.pptx";

//Configure AWS credentials and region
var region = Amazon.RegionEndpoint.USEast1;
var credentials = new Amazon.Runtime.BasicAWSCredentials("your-access-key", "your-secret-key");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,10 @@ public IActionResult Index()
}
public async Task<IActionResult> EditDocument()
{
//Your Azure Storage Account connection string
string connectionString = "Your_connection_string";

//Name of the Azure Blob Storage container
string containerName = "Your_container_name";

//Name of the Powerpoint file you want to load
string blobName = "PowerPointTemplate.pptx";

try
{
//Retrieve the document from Azure
MemoryStream stream = await GetDocumentFromAzure(connectionString, containerName, blobName);
MemoryStream stream = await GetDocumentFromAzure();

//Set the position to the beginning of the MemoryStream
stream.Position = 0;
Expand All @@ -52,7 +43,7 @@ public async Task<IActionResult> EditDocument()
if (shape.TextBody.Text == "Company History")
shape.TextBody.Text = "Company Profile";

//Saving the PowerPoint document to a MemoryStream
//Saving the PowerPoint file to a MemoryStream
MemoryStream outputStream = new MemoryStream();
pptxDocument.Save(outputStream);

Expand All @@ -75,11 +66,20 @@ public async Task<IActionResult> EditDocument()
/// <param name="bucketName"></param>
/// <param name="key"></param>
/// <returns></returns>
public async Task<MemoryStream> GetDocumentFromAzure(string connectionString, string containerName, string blobName)
public async Task<MemoryStream> GetDocumentFromAzure()
{
try
{
//Download the PowerPoint document from Azure Blob Storage
//Your Azure Storage Account connection string
string connectionString = "Your_connection_string";

//Name of the Azure Blob Storage container
string containerName = "Your_container_name";

//Name of the Powerpoint file you want to load
string blobName = "PowerPointTemplate.pptx";

//Download the PowerPoint from Azure Blob Storage
BlobServiceClient blobServiceClient = new BlobServiceClient(connectionString);
BlobContainerClient containerClient = blobServiceClient.GetBlobContainerClient(containerName);
BlobClient blobClient = containerClient.GetBlobClient(blobName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,33 +73,33 @@ public async Task<IActionResult> UploadDocument()

//Saves the PowerPoint document to MemoryStream
MemoryStream stream = new MemoryStream();
pptxDocument.Save(stream);

//Your Azure Storage Account connection string
string connectionString = "Your_connection_string";

//Name of the Azure Blob Storage container
string containerName = "Your_container_name";

//Name of the PowerPoint file you want to load
string blobName = "CreatePowerPoint.pptx";
pptxDocument.Save(stream);

//Upload the document to azure
await UploadDocumentToAzure(connectionString, containerName, blobName, stream);
await UploadDocumentToAzure(stream);

return Ok("PowerPoint document uploaded to Azure Blob Storage.");
return Ok("PowerPoint uploaded to Azure Blob Storage.");
}
/// <summary>
/// Upload file to Azure Blob cloud storage
/// </summary>
/// <param name="bucketName"></param>
/// <param name="key"></param>
/// <returns></returns>
public async Task<MemoryStream> UploadDocumentToAzure(string connectionString, string containerName, string blobName, MemoryStream stream)
public async Task<MemoryStream> UploadDocumentToAzure(MemoryStream stream)
{
try
{
//Download the PowerPoint document from Azure Blob Storage
//Your Azure Storage Account connection string
string connectionString = "Your_connection_string";

//Name of the Azure Blob Storage container
string containerName = "Your_container_name";

//Name of the PowerPoint file you want to load
string blobName = "CreatePowerPoint.pptx";

//Download the PowerPoint from Azure Blob Storage
BlobServiceClient blobServiceClient = new BlobServiceClient(connectionString);
BlobContainerClient containerClient = blobServiceClient.GetBlobContainerClient(containerName);
BlobClient blobClient = containerClient.GetBlobClient(blobName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,8 @@ public IActionResult Index()
}
public async Task<IActionResult> EditDocument()
{
//Your bucket name
string bucketName = "Your_bucket_name";

//Your service account key path
string keyPath = "Your_service_account_key_path";

//Name of the file to download from the Google Cloud Storage
string fileName = "PowerPointTemplate.pptx";

//Download the file from Google
MemoryStream memoryStream = await GetDocumentFromGoogle(bucketName, keyPath, fileName);
MemoryStream memoryStream = await GetDocumentFromGoogle();

//Create an instance of PowerPoint Presentation file
using (IPresentation pptxDocument = Presentation.Open(memoryStream))
Expand All @@ -48,7 +39,7 @@ public async Task<IActionResult> EditDocument()
if (shape.TextBody.Text == "Company History")
shape.TextBody.Text = "Company Profile";

//Saving the PowerPoint document to a MemoryStream
//Saving the PowerPoint to a MemoryStream
MemoryStream outputStream = new MemoryStream();
pptxDocument.Save(outputStream);

Expand All @@ -65,24 +56,31 @@ public async Task<IActionResult> EditDocument()
/// <param name="keyPath"></param>
/// <param name="fileName"></param>
/// <returns></returns>
public async Task<MemoryStream> GetDocumentFromGoogle(string bucketName, string keyPath, string fileName)
public async Task<MemoryStream> GetDocumentFromGoogle()
{
try
{
//Your bucket name
string bucketName = "Your_bucket_name";

//Your service account key path
string keyPath = "Your_service_account_key_path";

//Name of the file to download from the Google Cloud Storage
string fileName = "PowerPointTemplate.pptx";

//Create Google Credential from the service account key file
GoogleCredential credential = GoogleCredential.FromFile(keyPath);

//Instantiates a storage client to interact with Google Cloud Storage
StorageClient storageClient = StorageClient.Create(credential);

//Download a file from Google Cloud Storage
using (MemoryStream memoryStream = new MemoryStream())
{
await storageClient.DownloadObjectAsync(bucketName, fileName, memoryStream);
memoryStream.Position = 0;
MemoryStream memoryStream = new MemoryStream();
await storageClient.DownloadObjectAsync(bucketName, fileName, memoryStream);
memoryStream.Position = 0;

return memoryStream;
}
return memoryStream;
}
catch (Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,23 +74,14 @@ public async Task<IActionResult> UploadDocument()
stampShape.Fill.FillType = FillType.None;
stampShape.TextBody.AddParagraph("IMN").HorizontalAlignment = HorizontalAlignmentType.Center;

//Saves the PowerPoint document to MemoryStream
//Saves the PowerPoint to MemoryStream
MemoryStream stream = new MemoryStream();
pptxDocument.Save(stream);
pptxDocument.Save(stream);

//Your bucket name
string bucketName = "Your_bucket_name";
//Upload the file to Google
await UploadDocumentToGoogle(stream);

//Your service account key path
string keyPath = "Your_service_account_key_path";

//Name of the file to upload to Google Cloud Storage
string fileName = "CreatePowerPoint.pptx";

//Upload the document to Google
await UploadDocumentToGoogle(bucketName, keyPath, fileName, stream);

return Ok("PowerPoint document uploaded to Google Cloud Storage.");
return Ok("PowerPoint uploaded to Google Cloud Storage.");
}
/// <summary>
/// Upload file to Google
Expand All @@ -100,10 +91,19 @@ public async Task<IActionResult> UploadDocument()
/// <param name="fileName"></param>
/// <param name="stream"></param>
/// <returns></returns>
public async Task<MemoryStream> UploadDocumentToGoogle(string bucketName, string keyPath, string fileName, MemoryStream stream)
public async Task<MemoryStream> UploadDocumentToGoogle(MemoryStream stream)
{
try
{
//Your bucket name
string bucketName = "Your_bucket_name";

//Your service account key path
string keyPath = "Your_service_account_key_path";

//Name of the file to upload to Google Cloud Storage
string fileName = "CreatePowerPoint.pptx";

//Create Google Credential from the service account key file
GoogleCredential credential = GoogleCredential.FromFile(keyPath);

Expand Down

0 comments on commit f255de8

Please sign in to comment.