0

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

T.S.
  • 18,195
  • 11
  • 58
  • 78
Peter Sun
  • 1,675
  • 4
  • 27
  • 50
  • Minimum what you can do, is to catch the exception, do `ex.ToString()` and post it. So we can see the trace. Also see this https://stackoverflow.com/a/31755811/1704458 – T.S. Dec 16 '17 at 03:27
  • Posting same question twice [.net converting image jpg to jp2 using magick.net](https://stackoverflow.com/questions/47838226/net-converting-image-jpg-to-jp2-using-magick-net) – T.S. Dec 16 '17 at 03:31
  • added exception message to post – Peter Sun Dec 16 '17 at 04:32
  • Isn't it because you have `pathToSave_100` for read and write? Try change this `image.Write(pathToSave_100);` to some different name. – T.S. Dec 16 '17 at 15:44

0 Answers0