Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to upload memory file to amazon S3?

I want to upload a file from my memoryStream to amazon S3 server.

Here is the code:

public static bool memUploadFile(AmazonS3 client, MemoryStream memFile, string toPath)
{

    try
    {
        Amazon.S3.Transfer.TransferUtility tranUtility = new Amazon.S3.Transfer.TransferUtility(client);
        tranUtility.Upload(filePath, toPath.Replace("\\", "/"));

        return true;
    }
    catch (Exception ex)
    {
        return false;
    }

}

Then the error says,

"the best overload method match for 'Amazon.S3.Transfer.TransferUtility.Uplaod(string,string)' has some invalid arguments"

like image 953
Benny Ae Avatar asked Oct 04 '13 18:10

Benny Ae


People also ask

How do I upload files to AWS S3?

In the Amazon S3 console, choose the bucket where you want to upload an object, choose Upload, and then choose Add Files. In the file selection dialog box, find the file that you want to upload, choose it, choose Open, and then choose Start Upload. You can watch the progress of the upload in the Transfer pane.

How do I upload a large file to AWS?

Instead of using the Amazon S3 console, try uploading the file using the AWS Command Line Interface (AWS CLI) or an AWS SDK. Note: If you use the Amazon S3 console, the maximum file size for uploads is 160 GB. To upload a file that is larger than 160 GB, use the AWS CLI, AWS SDK, or Amazon S3 REST API.

What is the largest size file you can transfer to S3?

Individual Amazon S3 objects can range in size from a minimum of 0 bytes to a maximum of 5 TB. The largest object that can be uploaded in a single PUT is 5 GB.

How do I transfer local files to AWS S3?

Upload multiple files to AWS CloudShell using Amazon S3 You have two options for uploading files: AWS Management Console: Use drag-and-drop to upload files and folders to a bucket. AWS CLI: With the version of the tool installed on your local machine, use the command line to upload files and folders to the bucket.


1 Answers

Look at the Upload Method (stream, bucketName, key)

public static bool memUploadFile(AmazonS3 client, MemoryStream memFile, string toPath)
{
    try
    {
        using(Amazon.S3.Transfer.TransferUtility tranUtility =
                      new Amazon.S3.Transfer.TransferUtility(client))
        {
            tranUtility.Upload(memFile, toPath.Replace("\\", "/"), <The key under which the Amazon S3 object is stored.>);

            return true;
        }
    }
    catch (Exception ex)
    {
        return false;
    }
}
like image 196
Hamlet Hakobyan Avatar answered Oct 10 '22 23:10

Hamlet Hakobyan