Problemas com o Uploadify na recuperacao de parametro
Tenho uma pagina simples usando o plugin Uploadify para upload de imagens o meu arquivo Generic Handler esta fazendo a gravação corretamente e retornando a pasta e nome do arquivo gravado certinho mas não consigo recuperar este parâmetro de retorno dentro do plugin. Estes são os códigos:
Pagina ASPX
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="upload2.aspx.cs" Inherits="administracao_upload2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<link href="../js/Uploadfy/default.css" rel="stylesheet" type="text/css" />
<link href="../js/Uploadfy/uploadify.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../js/jquery-1.8.0.min.js"></script>
<script type="text/javascript" src="../js/Uploadfy/swfobject.js"></script>
<script type="text/javascript" src="../js/Uploadfy/jquery.uploadify.v2.1.0.min.js"></script>
</head>
<body>
<form id="form1" runat="server">
<div>
<br/>
<div class="demo">
<asp:FileUpload ID="FileUpload1" runat="server" />
</div>
<asp:Image ID="Image1" runat="server" />
<div id="preview"></div>
<img src="" id="foto" />
</div>
</form>
</body>
</html>
<script type = "text/javascript">
$(document).ready(function () {
$("#<%=FileUpload1.ClientID%>").uploadify({
'uploader': '../js/Uploadfy/uploadify.swf',
'script': '../Upload.ashx?p=teste',
'cancelImg': '../js/Uploadfy/cancel.png',
'folder': '../uploads',
'multi': true,
'removeCompleted': false,
'auto': true,
'onComplete': function(file, data, response) {
alert('The file ' + data + ' was successfully uploaded with a response of ');
},
'onUploadSuccess': function(file, data, response)
{
alert('The file ' + file.name + ' was successfully uploaded with a response of ' + response + ':' + data);
}
});
});
</script>
Pagina Upload.ashx
<%@ WebHandler Language="C#" Class="Upload" %>
using System;
using System.Web;
using System.IO;
public class Upload : IHttpHandler {
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
context.Response.Expires = -1;
try
{
HttpPostedFile postedFile = context.Request.Files["Filedata"];
string savepath = "";
string tempPath = "";
tempPath = context.Request["folder"];
//If you prefer to use web.config for folder path, uncomment below line:
//tempPath = System.Configuration.ConfigurationManager.AppSettings["FolderPath"];
savepath = context.Server.MapPath(tempPath);
string filename = postedFile.FileName;
if (!Directory.Exists(savepath))
Directory.CreateDirectory(savepath);
string novoNome=geraNome()+Path.GetExtension(filename);
postedFile.SaveAs(savepath + @"\" + novoNome);
context.Response.Write(tempPath + "/" + novoNome);
context.Response.StatusCode = 200;
}
catch (Exception ex)
{
context.Response.Write("Error:" + ex.Message);
}
}
public bool IsReusable {
get {
return false;
}
}
}
Obrigado
Discussão (1)
Carregando comentários...