Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting file url after upload amazon s3

I need to get file url after upload the file to amazons3 server. Here is my upload code. How to return amazons3 path ?

public static bool UploadToS3(string bucketName, string bucketFilePath, Byte[] localPath)
    {
        var client = Amazon.AWSClientFactory.CreateAmazonS3Client(Config.EmailServer.AwsAccessKey, Config.EmailServer.AwsSecretKey, Amazon.RegionEndpoint.EUWest1);

        PutObjectRequest request = new PutObjectRequest()
        {
            BucketName = bucketName,
            Key = bucketFilePath,
            InputStream = new MemoryStream(localPath),
            AutoCloseStream = true,
            CannedACL = S3CannedACL.PublicRead,
            StorageClass = S3StorageClass.ReducedRedundancy                
        };

        PutObjectResponse response = client.PutObject(request);
        return true;
    }
like image 566
erkan demir Avatar asked Jan 15 '14 08:01

erkan demir


People also ask

How do I find my Amazon S3 URL?

Get an S3 Object's URL #Navigate to the AWS S3 console and click on your bucket's name. Use the search input to find the object if necessary. Click on the checkbox next to the object's name. Click on the Copy URL button.

How do I find my upload URL on my Galaxy S3?

You can get the resource URL either by calling getResourceUrl or getUrl . AmazonS3Client s3Client = (AmazonS3Client)AmazonS3ClientBuilder. defaultClient(); s3Client. putObject(new PutObjectRequest("your-bucket", "some-path/some-key.

How do I get a Presigned URL?

To generate a presigned URL using the AWS Management ConsoleIn the Buckets list, choose the name of the bucket that contains the object that you want a presigned URL for. In the Objects list, select the object that you want to create a presigned URL for. On the Actions menu, choose Share with a presigned URL.

How do I view uploaded files on AWS S3?

In AWS Explorer, expand the Amazon S3 node, and double-click a bucket or open the context (right-click) menu for the bucket and choose Browse. In the Browse view of your bucket, choose Upload File or Upload Folder. In the File-Open dialog box, navigate to the files to upload, choose them, and then choose Open.


1 Answers

Simply you can generate download expiry link after upload completed.

example:

var expiryUrlRequest = new GetPreSignedUrlRequest()
                           .WithBucketName(BucketName)
                           .WithKey(Key)
                           .WithExpires(DateTime.Now.AddDays(10));

string url = _amazonS3Client.GetPreSignedURL(expiryUrlRequest);
like image 144
Yahya Younes Avatar answered Oct 29 '22 18:10

Yahya Younes