Asp.net implements Remote Image Upload Based on Web Services,

Source: Internet
Author: User

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

Related Article

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.