Flex結合ASP 實現文件上傳遇到的問題(學習筆記)

剛不久實現一個利用Flex結合ASP實現多文件上傳的功能,遇到了不少問題,雖說功能不大,卻學習到了不少。

具體實現方法在Flex一端代碼

	var request:URLRequest = new URLRequest("com/esri/solutions/DotNetSetvices/UpLoadFileService.aspx");
	filerefernce.upload(request);

在ASP中代碼大概如下:

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;

public partial class UpLoadFileService : System.Web.UI.Page
{
    string uploadFolder = "assets\\images\\view";
    protected void Page_Load(object sender, EventArgs e)
    {
        HttpFileCollection files = Request.Files;

        if (files.Count == 0)
        {
            Response.Write("錕斤拷錕斤拷直錕接鳳拷錕絞憋拷錕僥礆拷");
            Response.End();
        }

        string path = Server.MapPath(uploadFolder);//返回與 Web 服務器上的指定虛擬路徑相對應的物理文件路徑。

        path = path.Replace("DotNetSetvices\\", "");

        HttpPostedFile file = files[0];
        string savePath="";
        if (file != null && file.ContentLength > 0)
        {
            string pFileName = Request.Form["fileName"];
            string[] filenames= Directory.GetFiles(path);//獲得指定路徑下的所有文件的數組
            bool IsChanged = false;
            foreach(string pfiles in filenames) 
            {
                string pfilename=path+"\\"+pFileName;
                if (pfiles == pfilename)
                {
                    savePath = path + "\\1" + pFileName;
                    IsChanged = true;
                }
            }
            if (!IsChanged)
            {
                savePath = path + "\\" + pFileName;
            }
            file.SaveAs(savePath);
        }
    }
}
問題1:如何實現從Flex中調試進入ASP中?

利用VS打開網站,路徑設置爲ASP路徑,將要調試的Asp“設置爲起始頁”,並添加斷點,啓動調試,獲得Asp的URL地址,再將Flex中的URLRequest中路徑代碼修改爲如下:

	var request:URLRequest = new URLRequest("http://localhost:2625/DotNetSetvices/UpLoadFileService.aspx");
	filerefernce.upload(request);
添加斷點,啓動調試,就可以進入VS中調試ASP代碼。

問題2:flex彈出:“filereference.upload出現Error #2038: 文件 I/O 錯誤。”

出現這種錯誤可能的原因有以下幾點:

URL無效;

	 上傳文件大小超過服務器最大上傳限制或最大POST限制;
	 與服務器連接異常中斷;
	 上傳的文件爲空;
	 文件(夾)權限 。

由於我上傳了同名的文件,因此這屬於URL問題吧。後來修改代碼解決了問題

問題3:ASP中出現錯誤對路徑的訪問被拒絕。

對路徑中的文件夾右鍵“安全”,爲ASPNET用戶添加權限即可。但右鍵時突然發現沒有“安全”選項卡,後查閱資料發現只有磁盤格式爲NTFS的纔有“安全“選項卡,而我的代碼所在磁盤格式爲FAT32,需要將磁盤格式進行轉換。

問題4:如何將磁盤格式從FAT32轉爲NTFS?

開始→運行→鍵入cmd按回車,在窗口“command prompt”下,輸入命令“convert C: /FS:NTFS”按回車,重新啓動電腦,即將FAT32 轉換 NTSF 格式。注意:在“covert”的後面有一個空格,C是你要更改文件系統盤的卷標。



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章