我用SWFUpload自带的例子都不能上传文件!客户端一直报500错误,是什么原因,谢谢
错误如图所示
代码:
upload.aspx.cs文件内容:using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Collections.Generic;
public partial class upload : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
System.Drawing.Image thumbnail_image = null;
System.Drawing.Image original_image = null;
System.Drawing.Bitmap final_image = null;
System.Drawing.Graphics graphic = null;
MemoryStream ms = null;
try
{
// Get the data
HttpPostedFile jpeg_image_upload = Request.Files["Filedata"];
// Retrieve the uploaded image
original_image = System.Drawing.Image.FromStream(jpeg_image_upload.InputStream);
// Calculate the new width and height
int width = original_image.Width;
int height = original_image.Height;
int target_width = 100;
int target_height = 100;
int new_width, new_height;
float target_ratio = (float)target_width / (float)target_height;
float image_ratio = (float)width / (float)height;
if (target_ratio > image_ratio)
{
new_height = target_height;
new_width = (int)Math.Floor(image_ratio * (float)target_height);
}
else
{
new_height = (int)Math.Floor((float)target_width / image_ratio);
new_width = target_width;
}
new_width = new_width > target_width ? target_width : new_width;
new_height = new_height > target_height ? target_height : new_height;
// Create the thumbnail
// Old way
//thumbnail_image = original_image.GetThumbnailImage(new_width, new_height, null, System.IntPtr.Zero);
// We don't have to create a Thumbnail since the DrawImage method will resize, but the GetThumbnailImage looks better
// I've read about a problem with GetThumbnailImage. If a jpeg has an embedded thumbnail it will use and resize it which
// can result in a tiny 40x40 thumbnail being stretch up to our target size
final_image = new System.Drawing.Bitmap(target_width, target_height);
graphic = System.Drawing.Graphics.FromImage(final_image);
graphic.FillRectangle(new System.Drawing.SolidBrush(System.Drawing.Color.Black), new System.Drawing.Rectangle(0, 0, target_width, target_height));
int paste_x = (target_width - new_width) / 2;
int paste_y = (target_height - new_height) / 2;
graphic.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; /* new way */
//graphic.DrawImage(thumbnail_image, paste_x, paste_y, new_width, new_height);
graphic.DrawImage(original_image, paste_x, paste_y, new_width, new_height);
// Store the thumbnail in the session (Note: this is bad, it will take a lot of memory, but this is just a demo)
ms = new MemoryStream();
final_image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
// Store the data in my custom Thumbnail object
string thumbnail_id = DateTime.Now.ToString("yyyyMMddHHmmssfff");
Thumbnail thumb = new Thumbnail(thumbnail_id, ms.GetBuffer());
// Put it all in the Session (initialize the session if necessary)
List <Thumbnail> thumbnails = Session["file_info"] as List <Thumbnail>;
if (thumbnails == null)
{
thumbnails = new List <Thumbnail>();
Session["file_info"] = thumbnails;
}
thumbnails.Add(thumb);
Response.StatusCode = 200;
Response.Write(thumbnail_id);
}
catch
{
// If any kind of error occurs return a 500 Internal Server error
Response.StatusCode = 500;
Response.Write("An error occured");
Response.End();
}
finally
{
// Clean up
if (final_image != null) final_image.Dispose();
if (graphic != null) graphic.Dispose();
if (original_image != null) original_image.Dispose();
if (thumbnail_image!= null )thumbnail_image.Dispose();
if (ms != null) ms.Close();
Response.End();
}
}
}
客户端default.aspx.cs内容
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!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>SWFUpload Revision v2.1.0 Application Demo (ASP.Net 2.0) </title>
<link href="../css/default.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../swfupload/swfupload.js"> </script>
<script type="text/javascript" src="js/handlers.js"> </script>
<script type="text/javascript">
var swfu;
window.onload = function () {
swfu = new SWFUpload({
// Backend Settings
upload_url: "../applicationdemo.net/upload.aspx", // Relative to the SWF file
post_params : {
"ASPSESSID" : " <%=Session.SessionID %>"
},
// File Upload Settings
file_size_limit : "2048", // 2MB
file_types : "*.jpg",
file_types_description : "JPG Images",
file_upload_limit : "0", // Zero means unlimited
// Event Handler Settings - these functions as defined in Handlers.js
// The handlers are not part of SWFUpload but are part of my website and control how
// my website reacts to the SWFUpload events.
file_queue_error_handler : fileQueueError,
file_dialog_complete_handler : fileDialogComplete,
upload_progress_handler : uploadProgress,
upload_error_handler : uploadError,
upload_success_handler : uploadSuccess,
upload_complete_handler : uploadComplete,
// Flash Settings
flash_url : "../swfupload/swfupload_f9.swf", // Relative to this file
custom_settings : {
upload_target : "divFileProgressContainer"
},
// Debug Settings
debug: false
});
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div id="header">
<h1 id="logo"> <a href="../">SWFUpload </a> </h1>
<div id="version">v2.1.0 Beta </div>
</div>
<div id="content">
<h2>Application Demo (ASP.Net 2.0) </h2>
<div id="swfu_container" style="margin: 0px 10px;">
<div>
<button id="btnBrowse" type="button" style="padding: 5px;" onclick="swfu.selectFiles(); this.blur();"> <img src="images/page_white_add.png" style="padding-right: 3px; vertical-align: bottom;" alt="Add Icon" />Select Images <span style="font-size: 7pt;">(2 MB Max) </span> </button>
</div>
<div id="divFileProgressContainer" style="height: 75px;"> </div>
<div id="thumbnails"> </div>
</div>
</div>
</form>
</body>
</html>
我把服务器中的upload.aspx.cs文件内容全部注释掉,客户端的图片同样显示error.gif;
感觉是客户端脚本问题,可这些都是swfupload自带的例子,我一个字都没有改动
是不是服务器上的权限的等哪些方面还需要作进一步的设置?
[解决办法]
目录起码要有写权限吧
[解决办法]
上服务器端能看到实际的错误,另外权限...权限..
[解决办法]
顶顶更健康
[解决办法]
出现500错误的原因是很多的,一般来说,如果程序出错,那么在浏览器内会返回给用户一个友好的错误提示,统一称之为服务器500错误。
解决的方法就是您必须在http中能够正确的获得错误信息,方法为:请打开浏览器,选择工具,internet选项,高级,在高级中的浏览项目里面有一个“显示http友好错误提示”的复选框,请取消该复选框,这样您可以获得正确的错误提示。
在获得正确的错误提示之后,您就可以根据该错误提示检查您具体的出错原因了
大多数情况下,是一个网页中使用了多个@ 命令(调用多个网页往往忽略了这个问题),
去掉就OK 了。