访问以读取和写入Amazon Web Service上的文件

时间:2018-08-15 05:17:57

标签: .net amazon-web-services asp.net-mvc-4

请帮忙,enter image description here我对使用亚马逊网络服务是陌生的。我的asp.net mvc代码可以在本地主机上读写文件。但是在部署到亚马逊网络服务后,我得到了这样的错误 “找不到路径'C:\ inetpub \ wwwroot \ UploadedFiles \ ChurchMembers \ f3e3cdd6-8a0a-4029-ad9b-ad9d8b78c037.csv'的一部分。”我还观察到我也无法上传图像,下面是我读取文件的示例代码。我已经在网络上研究了答案,我无法真正分辨出我的代码还是需要在亚马逊服务器上设置的某种权限。你

        var path = "~/UploadedFiles/ChurchMembers";
        var fileName = parishId.ToString();
        var fullPath = path + "/" + parishId + ".csv";
        var filePath = System.IO.Path.GetFullPath(Server.MapPath(fullPath));

        fileHelper.UploadFileBase(file, path, fileName, new[] { ".csv" });

   public  FileInfo UploadFileBase(HttpPostedFileBase UploadedFile, string ServerPath, string FileName, string[] FileExtensions)
    {

        if (UploadedFile != null)
        {
            string fileExt = Path.GetExtension(UploadedFile.FileName);
            if (FileExtensions.Contains(fileExt.ToLower()))
            {
                try
                {
                    string fileDirectory = HostingEnvironment.MapPath(ServerPath);
                    string FilePath = Path.Combine(fileDirectory, FileName + fileExt.ToLower());
                    //string OldPath = Path.Combine(fileDirectory, OldFileName);
                    FileInfo file = new FileInfo(FilePath);

                    if (!Directory.Exists(fileDirectory)) Directory.CreateDirectory(fileDirectory);
                    if (file.Exists)
                    {
                        file.Delete();
                    }

                    UploadedFile.SaveAs(FilePath);
                    return file;
                }
                catch (Exception ex)
                {
                    return null;
                }
            }
            else return null;
        }
        else return null;
    }

0 个答案:

没有答案