Skip to content

Commit a391bbc

Browse files
author
Konduru Keerthi Konduru Ravichandra Raju
committed
Cloud Storage
1 parent 5dd7ffc commit a391bbc

File tree

6 files changed

+66
-69
lines changed

6 files changed

+66
-69
lines changed

Read-and-Save-document/Open-and-save-Word-document/AWS-S3-Bucket/Open-Word-document/Open-Word-document/Controllers/HomeController.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,10 @@ public IActionResult Index()
2121
}
2222
public async Task<IActionResult> EditDocument()
2323
{
24-
//Your AWS Storage Account bucket name
25-
string bucketName = "your-bucket-name";
26-
27-
//Name of the Word file you want to load from AWS S3
28-
string key = "WordTemplate.docx";
29-
3024
try
3125
{
3226
//Retrieve the document from AWS S3
33-
MemoryStream stream = await GetDocumentFromS3(bucketName, key);
27+
MemoryStream stream = await GetDocumentFromS3();
3428

3529
//Set the position to the beginning of the MemoryStream
3630
stream.Position = 0;
@@ -72,8 +66,14 @@ public async Task<IActionResult> EditDocument()
7266
/// <param name="bucketName"></param>
7367
/// <param name="key"></param>
7468
/// <returns></returns>
75-
public async Task<MemoryStream> GetDocumentFromS3(string bucketName, string key)
69+
public async Task<MemoryStream> GetDocumentFromS3()
7670
{
71+
//Your AWS Storage Account bucket name
72+
string bucketName = "your-bucket-name";
73+
74+
//Name of the Word file you want to load from AWS S3
75+
string key = "WordTemplate.docx";
76+
7777
//Configure AWS credentials and region
7878
var region = Amazon.RegionEndpoint.USEast1;
7979
var credentials = new Amazon.Runtime.BasicAWSCredentials("your-access-key", "your-secret-key");
@@ -100,7 +100,6 @@ public async Task<MemoryStream> GetDocumentFromS3(string bucketName, string key)
100100
await response.ResponseStream.CopyToAsync(stream);
101101

102102
return stream;
103-
104103
}
105104
}
106105
catch (Exception ex)

Read-and-Save-document/Open-and-save-Word-document/AWS-S3-Bucket/Save-Word-document/Save-Word-document/Controllers/HomeController.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -254,16 +254,10 @@ public async Task<IActionResult> UploadDocument()
254254

255255
//Saves the Word document to MemoryStream
256256
MemoryStream stream = new MemoryStream();
257-
document.Save(stream, FormatType.Docx);
258-
259-
//Your AWS Storage Account bucket name
260-
string bucketName = "your-bucket-name";
261-
262-
//Name of the Word file you want to upload
263-
string key = "CreateWord.docx";
257+
document.Save(stream, FormatType.Docx);
264258

265259
//Upload the document to AWS S3
266-
await UploadDocumentToS3(bucketName, key, stream);
260+
await UploadDocumentToS3(stream);
267261

268262
return Ok("Word document uploaded to AWS S3 Storage.");
269263
}
@@ -274,8 +268,14 @@ public async Task<IActionResult> UploadDocument()
274268
/// <param name="key"></param>
275269
/// <param name="stream"></param>
276270
/// <returns></returns>
277-
public async Task<MemoryStream> UploadDocumentToS3(string bucketName, string key, MemoryStream stream)
271+
public async Task<MemoryStream> UploadDocumentToS3(MemoryStream stream)
278272
{
273+
//Your AWS Storage Account bucket name
274+
string bucketName = "your-bucket-name";
275+
276+
//Name of the Word file you want to upload
277+
string key = "CreateWord.docx";
278+
279279
//Configure AWS credentials and region
280280
var region = Amazon.RegionEndpoint.USEast1;
281281
var credentials = new Amazon.Runtime.BasicAWSCredentials("your-access-key", "your-secret-key");

Read-and-Save-document/Open-and-save-Word-document/Azure-Blob-Storage/Open-Word-document/Open-Word-document/Controllers/HomeController.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,10 @@ public IActionResult Index()
2626
}
2727
public async Task<IActionResult> EditDocument()
2828
{
29-
//Your Azure Storage Account connection string
30-
string connectionString = "Your_connection_string";
31-
32-
//Name of the Azure Blob Storage container
33-
string containerName = "Your_container_name";
34-
35-
//Name of the Word file you want to load
36-
string blobName = "WordTemplate.docx";
37-
3829
try
3930
{
4031
//Retrieve the document from Azure
41-
MemoryStream stream = await GetDocumentFromAzure(connectionString, containerName, blobName);
32+
MemoryStream stream = await GetDocumentFromAzure();
4233

4334
//Set the position to the beginning of the MemoryStream
4435
stream.Position = 0;
@@ -81,10 +72,19 @@ public async Task<IActionResult> EditDocument()
8172
/// <param name="bucketName"></param>
8273
/// <param name="key"></param>
8374
/// <returns></returns>
84-
public async Task<MemoryStream> GetDocumentFromAzure(string connectionString, string containerName, string blobName)
75+
public async Task<MemoryStream> GetDocumentFromAzure()
8576
{
8677
try
8778
{
79+
//Your Azure Storage Account connection string
80+
string connectionString = "Your_connection_string";
81+
82+
//Name of the Azure Blob Storage container
83+
string containerName = "Your_container_name";
84+
85+
//Name of the Word file you want to load
86+
string blobName = "WordTemplate.docx";
87+
8888
//Download the Word document from Azure Blob Storage
8989
BlobServiceClient blobServiceClient = new BlobServiceClient(connectionString);
9090
BlobContainerClient containerClient = blobServiceClient.GetBlobContainerClient(containerName);

Read-and-Save-document/Open-and-save-Word-document/Azure-Blob-Storage/Save-Word-document/Save-Word-document/Controllers/HomeController.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -252,19 +252,10 @@ public async Task<IActionResult> UploadDocument()
252252

253253
//Saves the Word document to MemoryStream
254254
MemoryStream stream = new MemoryStream();
255-
document.Save(stream, FormatType.Docx);
256-
257-
//Your Azure Storage Account connection string
258-
string connectionString = "Your_connection_string";
259-
260-
//Name of the Azure Blob Storage container
261-
string containerName = "Your_container_name";
262-
263-
//Name of the Word file you want to load
264-
string blobName = "CreateWord.docx";
255+
document.Save(stream, FormatType.Docx);
265256

266257
//Upload the document to azure
267-
await UploadDocumentToAzure(connectionString, containerName, blobName, stream);
258+
await UploadDocumentToAzure(stream);
268259

269260
return Ok("Word document uploaded to Azure Blob Storage.");
270261
}
@@ -274,10 +265,19 @@ public async Task<IActionResult> UploadDocument()
274265
/// <param name="bucketName"></param>
275266
/// <param name="key"></param>
276267
/// <returns></returns>
277-
public async Task<MemoryStream> UploadDocumentToAzure(string connectionString, string containerName, string blobName, MemoryStream stream)
268+
public async Task<MemoryStream> UploadDocumentToAzure(MemoryStream stream)
278269
{
279270
try
280271
{
272+
//Your Azure Storage Account connection string
273+
string connectionString = "Your_connection_string";
274+
275+
//Name of the Azure Blob Storage container
276+
string containerName = "Your_container_name";
277+
278+
//Name of the Word file you want to load
279+
string blobName = "CreateWord.docx";
280+
281281
//Download the Word document from Azure Blob Storage
282282
BlobServiceClient blobServiceClient = new BlobServiceClient(connectionString);
283283
BlobContainerClient containerClient = blobServiceClient.GetBlobContainerClient(containerName);

Read-and-Save-document/Open-and-save-Word-document/Google-Cloud-Storage/Open-Word-document/Open-Word-document/Controllers/HomeController.cs

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,8 @@ public IActionResult Index()
2222
}
2323
public async Task<IActionResult> EditDocument()
2424
{
25-
//Your bucket name
26-
string bucketName = "Your_bucket_name";
27-
28-
//Your service account key path
29-
string keyPath = "Your_service_account_key_path";
30-
31-
//Name of the file to download from the Google Cloud Storage
32-
string fileName = "WordTemplate.docx";
33-
3425
//Download the file from Google
35-
MemoryStream memoryStream = await GetDocumentFromGoogle(bucketName, keyPath, fileName);
26+
MemoryStream memoryStream = await GetDocumentFromGoogle();
3627

3728
//Create an instance of WordDocument
3829
using (WordDocument wordDocument = new WordDocument(memoryStream, Syncfusion.DocIO.FormatType.Docx))
@@ -66,24 +57,31 @@ public async Task<IActionResult> EditDocument()
6657
/// <param name="keyPath"></param>
6758
/// <param name="fileName"></param>
6859
/// <returns></returns>
69-
public async Task<MemoryStream> GetDocumentFromGoogle(string bucketName, string keyPath, string fileName)
60+
public async Task<MemoryStream> GetDocumentFromGoogle()
7061
{
7162
try
7263
{
64+
//Your bucket name
65+
string bucketName = "Your_bucket_name";
66+
67+
//Your service account key path
68+
string keyPath = "Your_service_account_key_path";
69+
70+
//Name of the file to download from the Google Cloud Storage
71+
string fileName = "WordTemplate.docx";
72+
7373
//Create Google Credential from the service account key file
7474
GoogleCredential credential = GoogleCredential.FromFile(keyPath);
7575

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

7979
//Download a file from Google Cloud Storage
80-
using (MemoryStream memoryStream = new MemoryStream())
81-
{
82-
await storageClient.DownloadObjectAsync(bucketName, fileName, memoryStream);
83-
memoryStream.Position = 0;
80+
MemoryStream memoryStream = new MemoryStream();
81+
await storageClient.DownloadObjectAsync(bucketName, fileName, memoryStream);
82+
memoryStream.Position = 0;
8483

85-
return memoryStream;
86-
}
84+
return memoryStream;
8785
}
8886
catch (Exception ex)
8987
{

Read-and-Save-document/Open-and-save-Word-document/Google-Cloud-Storage/Save-Word-document/Save-Word-document/Controllers/HomeController.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -254,17 +254,8 @@ public async Task<IActionResult> UploadDocument()
254254
MemoryStream stream = new MemoryStream();
255255
document.Save(stream, FormatType.Docx);
256256

257-
//Your bucket name
258-
string bucketName = "Your_bucket_name";
259-
260-
//Your service account key path
261-
string keyPath = "Your_service_account_key_path";
262-
263-
//Name of the file to upload to Google Cloud Storage
264-
string fileName = "CreateWord.docx";
265-
266257
//Upload the document to Google
267-
await UploadDocumentToGoogle(bucketName, keyPath, fileName, stream);
258+
await UploadDocumentToGoogle(stream);
268259

269260
return Ok("Word document uploaded to Google Cloud Storage.");
270261
}
@@ -276,10 +267,19 @@ public async Task<IActionResult> UploadDocument()
276267
/// <param name="fileName"></param>
277268
/// <param name="stream"></param>
278269
/// <returns></returns>
279-
public async Task<MemoryStream> UploadDocumentToGoogle(string bucketName, string keyPath, string fileName, MemoryStream stream)
270+
public async Task<MemoryStream> UploadDocumentToGoogle(MemoryStream stream)
280271
{
281272
try
282273
{
274+
//Your bucket name
275+
string bucketName = "Your_bucket_name";
276+
277+
//Your service account key path
278+
string keyPath = "Your_service_account_key_path";
279+
280+
//Name of the file to upload to Google Cloud Storage
281+
string fileName = "CreateWord.docx";
282+
283283
//Create Google Credential from the service account key file
284284
GoogleCredential credential = GoogleCredential.FromFile(keyPath);
285285

0 commit comments

Comments
 (0)