Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- REST WCF Service Code:
- [OperationContract]
- [WebInvoke(UriTemplate = "uploadImage/{parameter1}")]
- void uploadImage(Stream fileStream);
- public void uploadImage(Stream fileStream)
- {
- string filePath = @"C:ImageUpload";
- FileStream filetoUpload = new FileStream(filePath, FileMode.Create);
- byte[] byteArray = new byte[10000];
- int bytesRead, totalBytesRead = 0;
- do
- {
- bytesRead = fileStream.Read(byteArray, 0, byteArray.Length);
- totalBytesRead += bytesRead;
- }
- while (bytesRead > 0);
- filetoUpload.Write(byteArray, 0, byteArray.Length);
- filetoUpload.Close();
- filetoUpload.Dispose();
- }
- protected void btnUpload_Click(object sender, EventArgs e)
- {
- string file = FileUpload1.FileName;
- RESTService1Client client = new RESTService1Client();
- byte[] bytearray = null;
- string name = "";
- if (FileUpload1.HasFile)
- {
- name = FileUpload1.FileName;
- Stream stream = FileUpload1.FileContent;
- stream.Seek(0, SeekOrigin.Begin);
- bytearray = new byte[stream.Length];
- int count = 0;
- while (count < stream.Length)
- {
- bytearray[count++] = Convert.ToByte(stream.ReadByte());
- }
- }
- WebClient wclient = new WebClient();
- wclient.Headers.Add("Content-Type", "image/jpeg");
- client.uploadImage(FileUpload1.FileContent);
- }
- [OperationContract]
- [WebInvoke(UriTemplate = "uploadImage/{parameter1}/{parameter2}")]
- void uploadImage(Stream fileStream, string fileName);
- public void uploadImage(Stream fileStream, string fileName)
- {
- string filePath = @"C:ImageUpload";
- using (FileStream filetoUpload = new FileStream(filePath + fileName, FileMode.Create))
- {
- byte[] byteArray = new byte[10000];
- int bytesRead = 0;
- do
- {
- bytesRead = fileStream.Read(byteArray, 0, byteArray.Length);
- if (bytesRead > 0)
- {
- filetoUpload.Write(byteArray, 0, bytesRead);
- }
- }
- while (bytesRead > 0);
- }
- }
- protected void btnUpload_Click(object sender, EventArgs e)
- {
- if (FileUpload1.HasFile)
- {
- RESTService1Client client = new RESTService1Client();
- client.uploadImage(FileUpload1.FileContent, Path.GetFileName(FileUpload1.FileName));
- }
- }
Add Comment
Please, Sign In to add comment