hello,
i have this code to upload async image and dispaly the image path after upload but it is not displaying image
<cc1:AsyncFileUpload OnClientUploadComplete="uploadComplete" runat="server" ID="AsyncFileUpload1"
Width="400px" UploaderStyle="Modern" CompleteBackColor="White" UploadingBackColor="#CCFFFF"
ThrobberID="imgLoader" OnUploadedComplete="FileUploadComplete" OnClientUploadStarted = "uploadStarted"/>
<asp:Image ID="imgDisplay" runat="server" Height="200px" />
<asp:Image ID="imgLoader" runat="server" ImageUrl="~/images/loader.gif" Width="60px" />
<script type="text/javascript">
function uploadStarted() {
$get("imgDisplay").style.display = "none";
document.getElementById("<%=imgDisplay.ClientID %>").style.display = "none";
}
function uploadComplete(sender, args) {
//var imgDisplay = $get("imgDisplay");
var imgDisplay = document.getElementById("<%=imgDisplay.ClientID %>");
//imgDisplay.src = "images/loader.gif";
imgDisplay.style.cssText = "";
var img = new Image();
img.onload = function () {
imgDisplay.style.cssText = "height:100px;width:100px";
imgDisplay.src = img.src;
};
img.src = "<%=ResolveUrl(UploadFolderPath) %>" ;
}
</script>
protected string UploadFolderPath = "~/DynamicImages/";
protected void FileUploadComplete(object sender, EventArgs e)
{
CheckFile ch = new CheckFile();
UploadFolderPath = ch.AyncUploadImages(AsyncFileUpload1);
}
public string AyncUploadImages(AsyncFileUpload FileUpload1)
{
string uploadFileName = "";
if (FileUpload1.HasFile)
{
ext = Path.GetExtension(FileUpload1.FileName).ToLower();
if (ext == ".jpg" || ext == ".jpeg" || ext == ".gif" || ext == ".png")
{
uploadFileName = Guid.NewGuid().ToString() + ext;
}
//FTP Server URL.
string ftp = ftppath;
//FTP Folder name. Leave blank if you want to upload to root folder.
string ftpFolder = domainname + "/DynamicImage/" + uploadFileName;
byte[] fileBytes = null;
//Read the FileName and convert it to Byte array.
string fileName = Path.GetFileName(uploadFileName);
FileUpload1.PostedFile.InputStream.Seek(0, SeekOrigin.Begin);
using (var binaryReader = new BinaryReader(FileUpload1.PostedFile.InputStream))
{
fileBytes = binaryReader.ReadBytes(FileUpload1.PostedFile.ContentLength);
}
try
{
//Create FTP Request.
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftp + ftpFolder);
request.Method = WebRequestMethods.Ftp.UploadFile;
//Enter FTP Server credentials.
request.Credentials = new NetworkCredential(username, password);
request.ContentLength = fileBytes.Length;
request.UsePassive = true;
request.UseBinary = true;
request.ServicePoint.ConnectionLimit = fileBytes.Length;
request.EnableSsl = false;
using (Stream requestStream = request.GetRequestStream())
{
requestStream.Write(fileBytes, 0, fileBytes.Length);
requestStream.Close();
}
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
path = returnpath + "/DynamicImage/" + uploadFileName;
response.Close();
}
catch (WebException ex)
{
throw new Exception((ex.Response as FtpWebResponse).StatusDescription);
}
}
HttpContext.Current.Session["Path"] = path;
return path;
}
so problem is if path of image is like
UploadFolderPath = "~/upload/filename" it shows image after upload but if image path is like
UploadFolderPath = "http://mycherry2.msonlinegroup.com/DynamicImage/99188c41-db49-4bff-9d4d-e0e9520fff5a.jpg";
it keeps on showing gif loading image
please advice