Hello developers,
I m working on the site where i m uploading a image with name and that uploaded file need to be store in another site. e.g. i m uploading image in www.abc.com that needs to be store in www.xyz.com file system. In short its a cross domain issue i m working on.
i used a webservice with querysting parameter for achieving this but querysting has limitation so whenever i send image bytearray then its not able to send the whole image because of its limitation.
i need another way to solve this proble, plz suggest me the way to solve the problem.
one important thing here i cant add webreference because the same solution have multiple output instatnces so i m using a webservice without any reference added in my solution. Another thing dont suggest me to use ftp client call because it takes creadential that i m not allowed to use.
i need a webservice method structure that accepts two parameter and the code that call that webmethod and pass these two parameters without any referece added.
plz help me.
my code is :
[webmethod]
public int StoreImage()
{
try
{
if (System.Web.HttpContext.Current.Request.QueryString["filename"] != null && System.Web.HttpContext.Current.Request.QueryString["imgByte"] != null)
{
Byte[] imgbyte = Encoding.ASCII.GetBytes(System.Web.HttpContext.Current.Request.QueryString["imgByte"].ToString());
System.IO.File.WriteAllBytes(Server.MapPath("\\images\\BannerImages\\") + System.Web.HttpContext.Current.Request.QueryString["filename"].ToString(), imgbyte);
return 1;
}
else
{
return 0;
}
}
catch
{
return 0;
}
}
[page code that call my webmethod]
string filename = fileuploader1.FileName;
Byte[] imgByte = null;
if (fileuploader1.HasFile && fileuploader1.PostedFile != null)
{
HttpPostedFile File = fileuploader1.PostedFile;
imgByte = new Byte[File.ContentLength];
File.InputStream.Read(imgByte, 0, File.ContentLength);
}
string ServeurURL = "http://xyz/SaveBannerImages.asmx/StoreImage?filename=" + filename + "&imgByte=" + imgByte;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(ServeurURL);
request.ContentType = "text/xml";
request.Method = "POST";
using (System.IO.Stream stream = request.GetRequestStream())
{
byte[] arrBytes = imgByte;
stream.Write(arrBytes, 0, arrBytes.Length);
}
WebResponse response = null;
try
{
response = request.GetResponse();
using (Stream stream = response.GetResponseStream())
{
using (StreamReader rdr = new StreamReader(stream, System.Text.Encoding.UTF8))
{
string strResponse = rdr.ReadToEnd();
idmsg.Text = strResponse;
}
}
}
catch
{
throw;
}
finally
{
if (response != null)
{
response.Close();
response = null;
}
}
above code is working but in querysting i cant send image byte array. so plz suggest me the efficient way to do this.