1.0 Introduction
NETS3 is an open source application build using Microsoft .NET technology. This application provides access to S3 contents in an easy and user friendly manner. Users are free to use the application as well as the source code as per their needs/ requirements. Feel free to report about Any changes, feedback or bugs at ak.tripathi@yahoo.com with subject line NETS3
2.0 Background
Now a days amazon cloud has been a very popular place for the storage. Storing any content on cloud helps us to overcome the data management issue.
This application may be used for easier access to cloud and for basic learning about amazon S3
3.0 Using the code
- Download NETS3 source code
- Search and double click NETS3.sln file
- Hit F5 button to run as well as debug the application.
3.1 How to Get all the buckets?
private DataTable GetAllBuckets()
{
DataTable buckets = new DataTable();
try
{
using (AmazonS3Client _s3Client =
new AmazonS3Client(AccessKeyId, SecretAccessKeyId))
{
ListBucketsResponse response = _s3Client.ListBuckets();
buckets.Columns.Add(new DataColumn("Name"));
buckets.Columns.Add(new DataColumn("CreationDate"));
DataRow row;
//Loop through the records obtained to create a data table
foreach (S3Bucket bucket in response.Buckets)
{
row = buckets.NewRow();
row[0] = bucket.BucketName;
row[1] = string.Format("{0:dd-MMM-yyyy hh:mm:ss}", Convert.ToDateTime( bucket.CreationDate));
buckets.Rows.Add(row);
}
}
}
catch (Exception err)
{
MessageBox.Show("Error Occured" + Environment.NewLine + err.Message);
}
return buckets;
}
3.2 How to get content(s) of any bucket?
using (AmazonS3Client _s3Client =
new AmazonS3Client(AccessKeyId, SecretAccessKeyId))
{
ListObjectsRequest listObjectReq = new ListObjectsRequest();
listObjectReq.WithBucketName(bucketName);
ListObjectsResponse resp = client.ListObjects(listObjectReq);
data.Columns.Add(new DataColumn("Key"));
data.Columns.Add(new DataColumn("LastModified"));
data.Columns.Add(new DataColumn("ETag"));
data.Columns.Add(new DataColumn("Owner"));
data.Columns.Add(new DataColumn("Size"));
data.Columns.Add(new DataColumn("StorageClass"));
DataRow row;
//Loop through the objects obtained to create a data table
foreach(S3Object obj in resp.S3Objects)
{
row = data.NewRow();
row["Key"] = obj.Key;
row["LastModified"] = string.Format("{0:dd-MMM-yyyy hh:mm:ss}", Convert.ToDateTime( obj.LastModified));
row["ETag"] = obj.ETag;
row["Owner"] = obj.Owner != null ? obj.Owner.DisplayName : "";
row["Size"] = obj.Size.ToString();
row["StorageClass"] = obj.StorageClass;
data.Rows.Add(row);
}
}
3.3 How to create new bucket?
using (AmazonS3Client _s3Client =
new AmazonS3Client(AccessKeyId, SecretAccessKeyId))
{
PutBucketResponse response = _s3Client.PutBucket(new PutBucketRequest().WithBucketName(bucketName));
}
3.4 How to Upload content to a bucket?
using (AmazonS3Client s3Client = new AmazonS3Client(AccessKeyId, SecretAccessKeyId))
{
//Create a unique id for the file
string fileName = "C:\Temp\SomeImage.png";
string key = Guid.NewGuid().ToString() + Path.GetExtension(fileName);
PutObjectRequest request = new PutObjectRequest();
request.WithBucketName(bucketName)
.WithCannedACL(S3CannedACL.PublicRead)
.WithKey(key).InputStream = StreamFile(fileName);
S3Response response = s3Client.PutObject(request);
}
private Stream StreamFile(string fileName)
{
Byte[] byteArray = File.ReadAllBytes(fileName);
MemoryStream mStream = new MemoryStream();
mStream.Write(byteArray, 0, byteArray.Length);
return mStream;
}
3.5 How to Download content from any bucket
private bool DownloadFile(string bucketName, string key)
{
string destination = "C:\Temp\";
if (!Directory.Exists(destination))
Directory.CreateDirectory(destination);
using (AmazonS3 _s3Client =
Amazon.AWSClientFactory.CreateAmazonS3Client(AccessKeyId, SecretAccessKeyId))
{
GetObjectRequest getObjectRequest = new GetObjectRequest().WithBucketName(bucketName).WithKey(key);
using (S3Response getObjectResponse = client.GetObject(getObjectRequest))
{
using (Stream s = getObjectResponse.ResponseStream)
{
using (FileStream fs = new FileStream( Path.Combine(destination, _fileName), FileMode.Create, FileAccess.Write))
{
byte[] data = new byte[32768];
int bytesRead = 0;
do
{
bytesRead = s.Read(data, 0, data.Length);
fs.Write(data, 0, bytesRead);
}
while (bytesRead > 0);
fs.Flush();
}
}
}
}
}
3.6 How to delete content from any bucket?
private bool DeleteFile(string fileName, string bucketName)
{
bool isSuccess = false;
try
{
using (AmazonS3 _s3Client =
Amazon.AWSClientFactory.CreateAmazonS3Client(AccessKeyId, SecretAccessKeyId))
{
DeleteObjectRequest request = new DeleteObjectRequest();
request.WithBucketName(bucketName).WithKey(fileName);
_s3Client.DeleteObject(request);
}
isSuccess = true;
}
catch (AmazonS3Exception amazonS3Exception)
{
MessageBox.Show("Error occured-" + Environment.NewLine + "Error Code: " + amazonS3Exception.ErrorCode + Environment.NewLine + "Message: " + amazonS3Exception.Message);
}
return isSuccess;
}
3.7 How to generate public url of any content?
private string GetPublicUrl(int expirationTime, string bucketName, string fileName, bool generateSecuredUrl)
{
string publicUrl = "";
using (AmazonS3 _s3Client =
Amazon.AWSClientFactory.CreateAmazonS3Client(AccessKeyId, SecretAccessKeyId))
{
GetPreSignedUrlRequest request = new GetPreSignedUrlRequest();
DateTime Expiration = DateTime.Now.AddHours(expirationTime);
request.WithBucketName(bucketName).WithKey(fileName).WithExpires(Expiration).WithProtocol(generateSecuredUrl ? Protocol.HTTPS : Protocol.HTTP);
publicUrl = client.GetPreSignedURL(request);
}
return publicUrl;
}
4.0 User Guide
- 1.0 Introduction
- 2.0 Technology Details
- 2.1 Pre-Requisites
- 2.2 How to Use
- 3.0 User Manual
- 3.1 Login
- 3.2 How to create New Bucket
- 3.3 How upload content to a bucket
- 3.4 How delete content from a bucket
- 3.5 How download content from a bucket
- 3.6 How generate URL of any content/ file
- 3.7 How change file download location
- 4.0 Feedback/ Bug Reporting
1.0 Introduction
NETS3 is an open source application build using Microsoft .NET technology. This application provides access to S3
contents in an easy and user friendly manner.
2.0 Technology Details
2.1 Pre-Requisites
Microsoft.NET Framework 3.5 or greater.
2.2 How to Use
Follow the steps below to use “NETS3”.
- Download the files
- Search for the directory Executable
- Search for the file NETS3.exe and double click the same to run
3.0 User Manual
3.1 Login
Run NETS3.exe
Enter Access Key Id and Secret Access Key Id and Hit login button
Successful login will redirect you to NETS3 Console, where you may do see your buckets listing and manipulate
these
3.2 How to create New Bucket
- 3.2.1 Once you are logged in to NETS3 Console. Hit CTRL+N
Enter the name of the bucket want to create and hit on create button
- 3.2.2 You will receive a message box,
3.3 How upload content to a bucket
- 3.3.1 Right Click on the bucket to which you want to upload the content
- 3.3.2 A Context menu will appear. Click (Left Click) on the “Upload Content”. This will bring a new
window to upload any file/ content,
- 3.3.3 Browse the file you wish to upload. You will see the browsed files in Selected File(s) grid with
add mark.
- 3.3.4 Click on “Upload” button to upload the selected content to Amazon S3.
3.4 How delete content from a bucket
- 3.4.1 Click on the bucket from the buckets tree from which you wish to delete the content. You will
see the files belonging to the bucket on right side grid.
- 3.4.2 Right click on the file/ content you wish to delete,
- 3.4.3 Click on “Delete” menu to delete the content.
3.5 How download content from a bucket
- 3.5.1 Click on the bucket from the buckets tree present in left, from which you wish to download the
content. You will see the files belonging to the bucket on right.
- 3.5.2 Right click on the file/ content you wish to Download,
- 3.5.3 Click on “Download” menu to download the content. By Default files are downloaded on your
desktop within a folder “NETS3Downloads”. You may change this location. See section 3.7 to
know how this path is changed.
3.6 How generate URL of any content/ file
- 3.6.1 Click on the bucket from the buckets tree present in left, from which you wish share the content
or file. You will see the files belonging to the bucket on right side.
- 3.6.2 Right click on the file/ content you wish to Share
- 3.6.3 Click on “Generate Url” menu to generate the url to share the content or file.
- 3.6.4 You may generate the secured url as per your requirement by varying Expiration Time, http or
http etc. Url may be given to any of your friend to access the contents for certain time.
3.7 How change file download location
- 3.7.1 Go to Setting >> Preferences
- 3.7.2 Browse the location where you wish to save the files downloaded.
4.0 Feedback/ Bug Reporting
Feel free to write your suggestion, feedback, user experiences to ak.tripathi@yahoo.com with subject line NETS3