Android Development upload picture encountered return FileNotFoundException

Source: Internet
Author: User

Purpose: Upload images with parameters

Environment: Client Development Android Studio, Server side: Visual Studio (C # ASP)

************************************************************************

When uploading a picture, I encountered a return filenotfoundexception, but always error on the client.

HttpURLConnection in Connection.getinputstream () Report Error FileNotFoundException

Java.io.FileNotFoundException: http://192.168.11.6/appHandler/UploadHandler.ashx (always thought to be unable to find this file)

So also has been looking for the client's error, in exchange for, or did not solve, are going crazy, put a period of time, today again to supplement this piece of development, slowly debugging, only to find that if the server side only accept parameters, do not process the picture and file this piece, will return to the server message normally, This is to know that there is a problem on the server side, the following code to post the problem:

 Public stringUploadvoicefile (HttpContext context) {stringFileName, FilePath; Httppostedfile Itemimagefile= Context. request.files["Filedata"]; FileName= ItemImageFile.FileName.Substring (ItemImageFile.FileName.LastIndexOf (".")); //FileName = Guid.NewGuid (). ToString (). Substring + DateTime.Now.ToShortDateString (). Replace ("/", "_") + file. Filename.substring (file. Filename.lastindexof ("."));        stringFilepathstr ="/upload/voice/"+ DateTime.Now.ToShortDateString (). Replace ("/","") +"/"; FilePath=HttpContext.Current.Server.MapPath (@FilePathStr); if(Itemimagefile! =NULL)        {            //If the directory is not available, create the upload directory            if(! Directory.Exists (FilePath))//There 's a problem with this piece.{directory.createdirectory (FilePath); }            if(Itemimagefile.contentlength >2097152)//image size cannot exceed 2M            {                return "{\ "result\": \ " -1\", \ "msg\": \ "picture size cannot exceed 2m! \"}"; } itemimagefile.saveas (FilePath+FileName); return "{\ "result\": \ "1\", \ "msg\": \ ""+ filepathstr + FileName +"\"}"; }        return "{\ "result\": \ " -1\", \ "msg\": \ "file data is empty! \"}"; }


is not to create a directory, and can not save the file, so thrown FileNotFoundException, also passed back to the client, thought to be unable to find the file:http://192.168.11.6/appHandler/UploadHandler.ashx

There are friends on the Internet, said to re-create a project on the OK, I here through the server local debugging is also possible, so the reason appears in the IIS file permissions this piece

Find the file directory to upload, right-click Security-"add-all Users, permissions: Full Control, Done!"

Shame ah, this a small problem wasted a few days of development time, written here for later notes, but also for your reference!

Android Development upload picture encountered return FileNotFoundException

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.