问题描述
我目前正在构建一个C#WebApi 2应用程序,该应用程序将上传到Amazon Elastic Beanstalk实例进行部署。到目前为止,我已经取得了成功,在本地计算机上,我刚刚完成了文件上传功能的测试,以便客户端上传图像。
I am currently building a C# WebApi 2 application that I will be uploading to an Amazon Elastic Beanstalk instance to deploy. I am having success so far, and on my local machine, I just finished testing the file upload capability in order for clients to upload images.
接受Web Api中的multipart / formdata并将临时文件(具有诸如BodyPart_24e246c7-a92a-4a3d-84ef-c1651416e667的随机名称)保存到App_Data文件夹。将该临时文件放入S3存储桶,然后在SQL Server数据库中创建对该文件的引用。
The way it goes is I accept the multipart/formdata in the Web Api and save the temp file (with a random name like BodyPart_24e246c7-a92a-4a3d-84ef-c1651416e667) to the App_Data folder. The temporary file is put into an S3 Bucket and I create a reference in my SQL Server database to it.
测试可以在本地单个或多个文件上传中正常运行,但是当我将应用程序部署到Elastic Beanstalk并尝试上传时,出现类似的错误路径 C:\inetpub\wwwroot\sbeAPI_deploy\App_Data\BodyPart_8f552d48-ed9b-4ec2-9986-88cbffd673ee的一部分,或者说完全拒绝访问。
Testing works fine with single or multiple file uploads locally but when I deploy the application to Elastic Beanstalk and try to upload I get errors like "Could not find a part of the path 'C:\inetpub\wwwroot\sbeAPI_deploy\App_Data\BodyPart_8f552d48-ed9b-4ec2-9986-88cbffd673ee'" or a similar one saying access is denied altogether.
我已经尝试了几个小时的在线解决方案,但是AWS文档无处不在,教程/其他问题似乎已经过时了。我相信这与没有权限在EC2服务器上写入临时文件有关,但是我不知道如何解决它。
I have been trying to find the solution online for a few hours now, but the AWS documentation is all over the place and tutorials/other questions seem to be outdated. I believe it has something to do with not having permission to write the temporary files on the EC2 server, but I can't figure out how to fix it.
非常感谢
推荐答案
自2013年4月以来这已经成为可能,另请参见:基本上,您执行的步骤需要执行以下操作:
This is already possible since April 2013, see also here: Basically the steps you need to perform are the following:
- 通过解决方案资源管理器在项目的顶层创建一个名为.ebextensions的文件夹 >
- 在此文件夹中添加您的配置文件,例如 myapp.config (用您的Elastic Beanstalk的应用名称替换myapp)
- 添加代码显示在您刚创建的此配置文件下方。将
MyApp
替换为在Visual Studio中显示的项目名称(而非解决方案名称) -
所有设置!确保 App_Data 中有一个文件,否则Visual Studio不会发布该文件。
- Create a folder called .ebextensions in the top-level of your project through the solution explorer
- Add in this folder your configuration file e.g myapp.config (replace myapp with your Elastic Beanstalk's app name)
- Add the code displayed underneath to this configuration file you just created. Replace
MyApp
with your project name (not solution name) displayed in Visual Studio All set!! Be sure there's a file within App_Data otherwise Visual Studio won't publish it.
{
"containercommands": {
"01-changeperm": {
"command": "icacls \"C:/inetpub/wwwroot/MyApp_deploy/App_Data\" /grant DefaultAppPool:(OI)(CI)"
}
}
}
这篇关于如何为Elastic beantalk Windows应用程序设置文件夹权限?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!