I am a developer and currently working on a project that will run on a private Windows 2012 server. I know little about windows permissions and how an ASP.net application works in terms of permissions. The server currently has the latest asp.net and is using IIS7 express.
The application I am working utilizes an HTML page that a user can take a picture from a device and upload the picture to a directory on another server. Currently, for testing, I am copying to a local folder on the server. The HTML page calls a web handler by JQUERY/AJAX. In my web handler, I am trying to manipulate the image by converting it to another format with a library called Magick.NET. The image that I uploaded shows up in the destination folder (currently to a test folder), but when trying to convert the image, I get an error: "permission denied, unable to open the image". Is this a permission issue? Or an 'I don't know how to use the Magick.NET library' issue?
If it is a permission issue, what information do I need to convey to the system admin. I don't speak windows admin security.
If the latter, the hell am I doing wrong? Or can someone give me a better library? Or is there a better way to do this?
Part of my webhandler.
context.Response.ContentType = "text/plain";
try
{
string dirFullPath = HttpContext.Current.Server.MapPath("~/MediaUploader/");
string[] files;
int numFiles;
files = System.IO.Directory.GetFiles(dirFullPath);
numFiles = files.Length;
numFiles = numFiles + 1;
string str_image = "";
foreach (string s in context.Request.Files)
{
HttpPostedFile file = context.Request.Files[s];
string fileName = file.FileName;
string fileExtension = file.ContentType;
if (!string.IsNullOrEmpty(fileName))
{
fileExtension = Path.GetExtension(fileName);
str_image = "MyPHOTO_" + numFiles.ToString() + fileExtension;
string pathToSave_100 = HttpContext.Current.Server.MapPath("~/MediaUploader/") + str_image;
file.SaveAs(pathToSave_100); //saves to the directory just fine.
using (MagickImage image = new MagickImage(pathToSave_100))
{
image.Format = Magick.jp2
image.Write(pathToSave_100); //get error here:
}
}
}
// database record update logic here ()
context.Response.Write(str_image);
}
Exception String:
ImageMagick.MagickBlobErrorException: unable to open image 'test.jp2': Permission denied @ error/blob.c/OpenBlob/3323 at ImageMagick.MagickExceptionHelper.Check(IntPtr exception) at ImageMagick.MagickImage.NativeMagickImage.WriteFile(MagickSettings settings) at ImageMagick.MagickImage.Write(String fileName) at fileUploadHandler.ProcessRequest(HttpContext context) in C:\Users\PSun\Desktop\PhotoApp\Solution\PhotoApp\PhotoApp\fileUploadHandler.ashx:line 40