1

I want to aceess iphone camera through web app and take picture annd save it to my computer. I am able to access camera but not able to save the picture from iphone to computer.

<form action="upload.aspx" method="post" enctype="multipart/form-data">
<input type="file" id="files" runat="server" name="files" 
        accept="image/*" capture="camera"  />

</form>

upload.aspx
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

namespace PartsMobile
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.Files["files"] != null)
            {
                HttpPostedFile MyFile = Request.Files["files"];
                //Setting location to upload files
                //string TargetLocation = Server.MapPath("~/Files");
                string TargetLocation =
                   @"c:\Projects3\Files";
                try
                {
                    if (MyFile.ContentLength > 0)
                    {
                        //Determining file name
                        string FileName = MyFile.FileName;
                        string str = Path.GetFileName(FileName);
                        //Determining file size
                        int FileSize = MyFile.ContentLength;
                        //Creating a byte array corresponding to file size.
                        byte[] FileByteArray = new byte[FileSize];
                        //Posted file is being pushed into byte array.
                        MyFile.InputStream.Read(FileByteArray, 0, FileSize);
                        //Uploading properly formatted file to server.
                        MyFile.SaveAs(Path.Combine(TargetLocation, str));
                        var invalidChars = Path.GetInvalidFileNameChars();
                    }
                }
                catch (Exception BlueScreen)
                {
                    //Handle errors
                }
            }
        }
    }
}
osaka
  • 328
  • 3
  • 11
  • Do you get any errors? What do you see debugging the web app? – Alexei Levenkov Dec 12 '13 at 00:05
  • @Alexei "It gives page cannot be displayed error. But I am able to save through desktop IE to computer location". – osaka Dec 12 '13 at 15:24
  • I doubt that Visual Studio (or WinDbg) gives "page cannot be displayed" error - I'm not sure how you are trying to debug your C# code... At very least look at logs generated by code hidden behind `// Handle errors` comment and post it here. Side note: for ASP.Net fatal exceptions are not called "blue screen", but rather "yellow screen of death" (ysod) - you can find many useful suggestions on handling such cases like http://stackoverflow.com/questions/878628/can-the-asp-net-yellow-screen-of-death-ysod-be-generated-on-demand-or-captured. – Alexei Levenkov Dec 12 '13 at 19:27
  • I finally solved it. It was permissions issue. I added app pool a/c to folder and that solved the issue. Thanks for your help. – osaka Dec 18 '13 at 16:13

1 Answers1

0

I finally solved it. It was permissions issue. I added app pool a/c to folder and that solved the issue. Thanks for your help

osaka
  • 328
  • 3
  • 11