Reputation: 3914
I have created a WebApi project and deployed this as a serverless application to AWS Lambda. It all works fine except that for one method, I need to read from a file. I can see that this file is deployed as it's in the zip file that gets pushed up but for some reason, when I come to read from it in the code, it can't find it.
I've tried both embedded resource and content for build action but neither seem to work. Is there something in AWS that needs configuring so that my serverless application can access local files?
Upvotes: 1
Views: 1302
Reputation: 1005
For anyone that needs more detail. Add your embedded files into your .csproj file as below (resources is your folder, note the "resources\" in .csproj and "resources/" in .cs):
<ItemGroup>
<Content Include="resources\*.*">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
In your .cs file, to get the file path:
var path = Path.Combine(Directory.GetCurrentDirectory(), "resources/example.txt");
Upvotes: 3