Question

Currently I'm creating an app using IntelXDK to upload image from devices to my server. The problem currently I'm encountering is, how to code my backend so that it can receive the upload file from mobile device?

In PHP, I only know that the file upload requires:

  1. <input type="file" name="file" />
  2. then use $FILES["file"] to save it into storage

And is almost similar in .Net as well. But I'm still couldn't think of how to receive the file once it is uploaded via mobile. Would be great if someone share or advise the missing part (.Net and PHP).

Was it helpful?

Solution

In ASP.net server side use webservice receive in byte format and save that as you want.

Code sample refrence link http://www.codeproject.com/Articles/22985/Upload-Any-File-Type-through-a-Web-Service

[WebMethod]

    public string UploadFile(byte[] f, string fileName)
    {
        // the byte array argument contains the content of the file
        // the string argument contains the name and extension
        // of the file passed in the byte array
        try
        {
            // instance a memory stream and pass the
            // byte array to its constructor
            MemoryStream ms = new MemoryStream(f);

            // instance a filestream pointing to the
            // storage folder, use the original file name
            // to name the resulting file
            FileStream fs = new FileStream
                (System.Web.Hosting.HostingEnvironment.MapPath
                ("~/TransientStorage/") +
                fileName, FileMode.Create);

            // write the memory stream containing the original
            // file as a byte array to the filestream
            ms.WriteTo(fs);

            // clean up
            ms.Close();
            fs.Close();
            fs.Dispose();

            // return OK if we made it this far
            return "OK";
        }
        catch (Exception ex)
        {
            // return the error message if the operation fails
            return ex.Message.ToString();
        }
    }
}

}

OTHER TIPS

For more information about uploading files to a server: https://software.intel.com/en-us/node/493213

If you are aware of ASP.NET Web API 2, have a look at this sample:

http://aspnet.codeplex.com/sourcecontrol/latest#Samples/WebApi/FileUploadSample/

Also, check these ones:

http://damienbod.wordpress.com/2014/03/28/web-api-file-upload-single-or-multiple-files/

http://www.asp.net/web-api/overview/working-with-http/sending-html-form-data,-part-2

http://www.c-sharpcorner.com/UploadFile/2b481f/uploading-a-file-in-Asp-Net-web-api/

Check these SO links:

How To Accept a File POST

File upload Jquery WebApi

I think, with above links, you will be surely able to create service that intakes file uploaded from a form.

Hope it helps you...

All the best...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top