首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从ASP.NET应用程序直接将文件上传到亚马逊S3

问从ASP.NET应用程序直接将文件上传到亚马逊S3
EN

Stack Overflow用户
提问于 2008-09-22 21:39:17
回答 6查看 21.4K关注 0票数 28

我的ASP.NET应用程序将占用大量的带宽和存储空间。如何设置ASP.NET上传页面,以便用户上传的文件将直接转到亚马逊S3,而无需使用我的web服务器的存储空间和带宽?

EN

回答 6

Stack Overflow用户

回答已采纳

发布于 2008-09-22 21:50:19

更新2016年2月:

AWS SDK现在可以处理更多此类问题。查看how to build the form和how to build the signature。假设您在将内容发送到S3之前不需要对内容进行任何处理,那么这应该可以防止您需要在自己的一端使用带宽。

票数 27
EN

Stack Overflow用户

发布于 2009-02-03 17:00:46

如果您需要上传大文件并显示进度条,则应考虑使用flajaxian component。

它使用闪存直接上传文件到亚马逊s3,节省您的带宽。

票数 4
EN

Stack Overflow用户

发布于 2016-02-18 18:16:09

通过asp.net将文件上传到亚马逊S3的最好、最简单的方法。请看下面我的博客帖子。我想这个会有帮助的。在这里,我已经解释了从添加API到创建S3密钥、安装Amazon SDK和编写上传文件的代码。以下是使用asp.net C#将文件上传到亚马逊S3的示例代码。

代码语言:javascript
复制
using System
using System.Collections.Generic
using System.Linq
using System.Web
using Amazon
using Amazon.S3
using Amazon.S3.Transfer
/// 
/// Summary description for AmazonUploader
/// 
public class AmazonUploader
{
        public bool sendMyFileToS3(System.IO.Stream localFilePath, string bucketName, string subDirectoryInBucket, string fileNameInS3)
        {
        // input explained :
        // localFilePath = we will use a file stream , instead of path
        // bucketName : the name of the bucket in S3 ,the bucket should be already created
        // subDirectoryInBucket : if this string is not empty the file will be uploaded to
            // a subdirectory with this name
        // fileNameInS3 = the file name in the S3
    // create an instance of IAmazonS3 class ,in my case i choose RegionEndpoint.EUWest1
    // you can change that to APNortheast1 , APSoutheast1 , APSoutheast2 , CNNorth1
    // SAEast1 , USEast1 , USGovCloudWest1 , USWest1 , USWest2 . this choice will not
    // store your file in a different cloud storage but (i think) it differ in performance
    // depending on your location


        IAmazonS3 client = new AmazonS3Client("Your Access Key", "Your Secrete Key", Amazon.RegionEndpoint.USWest2);

    // create a TransferUtility instance passing it the IAmazonS3 created in the first step
    TransferUtility utility = new TransferUtility(client);
    // making a TransferUtilityUploadRequest instance
    TransferUtilityUploadRequest request = new TransferUtilityUploadRequest();

    if (subDirectoryInBucket == "" || subDirectoryInBucket == null)
    {
        request.BucketName = bucketName; //no subdirectory just bucket name
    }
    else
    {   // subdirectory and bucket name
        request.BucketName = bucketName + @"/" + subDirectoryInBucket;
    }
    request.Key = fileNameInS3 ; //file name up in S3
    //request.FilePath = localFilePath; //local file name
    request.InputStream = localFilePath;
    request.CannedACL = S3CannedACL.PublicReadWrite;
    utility.Upload(request); //commensing the transfer

    return true; //indicate that the file was sent
}
}

在这里,您可以使用函数sendMyFileToS3向亚马逊S3上传文件流。有关更多详细信息,请查看以下链接中的我的博客。

Upload File to Amazon S3 via asp.net

我希望上面提到的链接能有所帮助。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/117810

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档