Solved

Upload file to my Amazon S3 account through my separate ASP.Net server

Posted on 2013-06-13
5
1,357 Views
Last Modified: 2014-11-12
Hello,
Before I try to do it, I'd like to know If and How can I do it…
1) I have an Amazon S3 account.
2) I have an ASP.Net Server located elsewhere (that currently stores the files locally).
I'd like to use my Amazon S3 account as a storage place for files and use it through My ASP.Net Server. I'd like to perform two main tasks:
1) Upload file from a Client Browser (hopefully directly) to Amazon S3.
2) Get a Tree List of my files at my Amazon S3 and display it at the Client Browser.
See a diagram attached below.
Questions:
1) I suppose I Must install AWS SDK for .NET (http://aws.amazon.com/sdkfornet/). Do I? or can I just add few DLL References to my ASP.Net project?
2) Can you give me some code/references to start with? But please not an "auto generated code" – I'd like to write it myself and integrate it with my existing ASP.Net code.
Thanks a lot, Aryeh.
 Flow Diagram of what I expect
0
Comment
Question by:tuchfeld
  • 4
5 Comments
 
LVL 23

Assisted Solution

by:Roopesh Reddy
Roopesh Reddy earned 500 total points
ID: 39247903
Hi,

You can directly upload the files to Amazon. Unfortunately, i don't know on sending files to Amazon. May be Amazon's SDK will help you to do that!

A blog post on uploading file - http://roopeshreddy.wordpress.com/2012/02/27/viewing-uploaded-file/

Once you get the file in to ASP.NET server, then you can push it to Amazon - http://www.cloudcomputingetc.com/2011/08/upload-files-to-amazon-s3-bucket-using.html

Hope it helps u...
0
 

Accepted Solution

by:
tuchfeld earned 0 total points
ID: 39268816
Thanx,
Actually all I needed is AWSSDK.dll (5M).
Here is a good samples code package.
And here is a code for listing directory recursively in VB.Net:
Imports Amazon
Imports Amazon.S3
Imports Amazon.S3.Model
Imports System.IO

Const bucketName As String = "***"
client As AmazonS3 = Amazon.AWSClientFactory.CreateAmazonS3Client(MY_AWS_ACCESS_KEY_ID, MY_AWS_SECRET_KEY)
List_Folder("MM/Music/Eng_man/Flat/Classics/")

Private Sub List_Folder(ByVal prefix As String)
    Dim request As New ListObjectsRequest()
    request.BucketName = bucketName
    request.WithPrefix(prefix)
    Dim response As ListObjectsResponse = client.ListObjects(request)
    For Each entry As S3Object In response.S3Objects
        Dim entry_Key As String = entry.Key
        Dim entry_Size As Long = entry.Size
        If entry_Key.EndsWith("/") AndAlso entry_Size = 0 Then
            If entry_Key <> prefix Then
                List_Folder(entry_Key)
            End If
        Else
            ResultsTextBox.Text += String.Format("{0} ({1})" & vbCrLf, entry_Key, entry_Size)
        End If
    Next
End Sub

Open in new window

And here is code for Uploading a file:
Public Sub UploadFileToS3(ByVal toWhichBucketName As String, ByVal uploadAsFileName As String, ByVal fileStream As Stream, ByVal filePermission As S3CannedACL, ByVal storageType As S3StorageClass)
    Dim client As AmazonS3 = Amazon.AWSClientFactory.CreateAmazonS3Client(MY_AWS_ACCESS_KEY_ID, MY_AWS_SECRET_KEY)
    Dim request As New PutObjectRequest()
    request.WithInputStream(fileStream)
    request.WithBucketName(toWhichBucketName)
    request.WithKey(uploadAsFileName)
    request.CannedACL = filePermission
    request.StorageClass = storageType
    client.PutObject(request)
End Sub

Open in new window

0
 

Author Comment

by:tuchfeld
ID: 39269129
I've requested that this question be closed as follows:

Accepted answer: 500 points for roopeshreddy's comment #a39247903
Assisted answer: 0 points for tuchfeld's comment #a39268816

for the following reason:

No much details in reply. but thanks anyway.
0
 

Author Comment

by:tuchfeld
ID: 39269130
opps. no need for recursive calling List_Folder(entry_Key)
just use the folders value.
0
 

Author Closing Comment

by:tuchfeld
ID: 39283761
Thanks for encouraging me to go on searching and finding the solution.
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Steve Terp was featured in a video created by CRN about how "Channel Is Crucial To Market Disruption". Click on View source to see the video and article
Most of the applications these days are on Cloud. Cloud is ubiquitous with many service providers in the market. Since it has many benefits such as cost reduction, software updates, remote access, disaster recovery and much more.
Steps to create a PostgreSQL RDS instance in the Amazon cloud. We will cover some of the default settings and show how to connect to the instance once it is up and running.
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question