Asp.net implements Remote Image Upload Based on Web Services,
This example describes how to use asp.net to remotely upload images based on Web Services. We will share this with you for your reference. The details are as follows:
Page call code: Add Web references
HttpFileCollection files = HttpContext. current. request. files; string filePath = files [0]. fileName; string fileName = filePath. substring (filePath. lastIndexOf ("//") + 1); byte [] datas = new byte [files [0]. contentLength]; System. IO. stream fs; localhost. webService web = new localhost. webService (); fs = (System. IO. stream) files [0]. inputStream; // read the input stream into a two-dimensional array fs. read (datas, 0, files [0]. contentLength); fs. close (); Response. write (web. uploadFile (datas, fileName ));
Code in Web Service
[WebMethod (Description = "Upload server image information, whether the returned result is successful")] public string UploadFile (byte [] fs, string fileName) {// create a memory stream to write the array into the memory stream MemoryStream memory = new MemoryStream (fs); // write the memory into the file stream FileStream = new FileStream (HttpContext. current. server. mapPath (". ") +" // images "+ fileName, FileMode. create); // write the memory stream into the memory of the FileStream stream. writeTo (stream); stream. close (); memory = null; stream = null; return "the file is uploaded successfully! ";}
I hope this article will help you design your asp.net program.
Articles you may be interested in:
- ASP. NET stores images in binary format into the database
- Asp.net saves an image as a binary value to the instance code in the Xml file.
- Asp.net (c #) implements code for accessing binary images from sqlserver
- ASP. NET
- Implementation of ASP. NET gradient display images
- Three typical ASP. NET image processing problems
- Examples of Image Display Methods in ASP. NET
- Asp.net implements two methods for outputting images in binary streams