I deploy a web app based on ASP.NET Core to Azure with Visual Studio 2019. Everything is ok except the upload images feature that actually accesses to folder/file. Thanks a lot for your suggestions.
public string UploadFile(IFormFile image)
{
if (image == null) return null;
try
{
string fileName = Guid.NewGuid().ToString() image.FileName;
string filePath = Path.Combine(_hostingEnvironment.WebRootPath, "Images", "ProductImages", fileName);
var extension = new[] { "image/jpg", "image/png", "image/jpeg" };
if (!extension.Contains(image.ContentType))
return null;
using (FileStream file = new FileStream(filePath, FileMode.Create))
{
image.CopyTo(file);
}
return fileName;
}
catch (Exception ex)
{
throw;
}
}
Error:
An unhandled exception occurred while processing the request. IOException: Read-only file system
CodePudding user response:
add FileAccess Permission
FileStream fileStream = new FileStream(path, FileMode.Create, FileAccess.Write);
CodePudding user response:
I have test your code and found it works fine in local. So I try to deploy this app to azure webapp (linux platform).
And also encountered this situation. So I check the application settings in azure portal.
Solution
Delete WEBSITES_RUN_FROM_PACKAGE
option at application settings in azure portal.
Why and How to solve it
Maybe there are some settings in publishsettings file cause the issue, you can download the publishsettings from azure portal.
And import into your IDE (like vs2019), or you can try to use another pc to deploy the app to prevent generate WEBSITES_RUN_FROM_PACKAGE
.