none
請問要如何接收 Flash 上傳的檔案 RRS feed

  • 問題

  • 因為要能讓使用者一次選取一堆檔案進行上傳,因此使用 Flash 製作了上傳介面。

    但遇到問題:
    一般若是使用 html 上傳單一檔案的話像這樣:

    In upload.html

    ...
    <body>
        <form id="form1" enctype="multipart/form-data"
              method="post" action="Default.aspx" runat="server">
            <input name="File" type="file" runat="server" /><br />
            <input type="submit" value="上傳" />
        </form>
    </body>
    ...

     

    In Default.aspx
    Protected Sub Page_Load(...) ...
        Try
            Dim uploadFile As HttpPostedFile = Request.Files("File")
            '存檔
            uploadFile.SaveAs(Server.MapPath("") & "\" & _
              Path.GetFileName(Request.Files("File").FileName))
        Catch ex As Exception
            Response.Write("發生錯誤!")
        End Try
    End Sub

     

    使用者在 upload.html 選好檔案,然後送出,就沒問題了,檔案能正確的傳送
    但是在 Flash 中我指定了伺服器的 Default.aspx 為接收上傳處理的應用程式
    結果卻不行.....

    Flash 端會收到 IO Error 的錯誤....

    據我所知 Flash 傳送的東西一樣是:
    ˙使用 HTTP 的 Post 方式
    ˙Content-Type 也是 multipart/form-data


    其它...還有什麼不一樣嗎??

    若是與傳統 html 的傳檔不一樣的話,server 端的接收程式該怎麼做呢?

     


    ps. Flash 的部分已經使用能夠接收的網頁確定過沒有問題

     

     

     

    麻煩大大了,謝謝~

    2008年3月26日 下午 05:20

解答

  • 你可以換個寫法試試,

     

    Code Snippet

    Dim uploadFile As HttpPostedFile = Request.Files(0)

    '存檔
    uploadFile.SaveAs(Server.MapPath("") & "\" & _
       Path.GetFileName(uploadFile.FileName))

     

     

    之前也做過一次用flash傳檔,
    不過flash不是我寫的.

    因此不知道flash用的物件名稱是甚麼.

    所以就直接用Request.Files(0)來取得上傳的資料中第一個檔案物件.

    或許你的情況只是因為flash中上傳檔案的欄位名稱不是File而已.

    2008年3月27日 上午 02:20

所有回覆

  • MultiPowUpload control

      Upload files over Flash Movie.

    http://www.element-it.com/MultiPowUpload.ASPX

     

    This component is a FREE, but requirement for this type of License: Back Link to Us.

    Read more about this in MultiPowUpload's EULA.

    MultiPowUpload is easy client-side solution that can be used to perform file uploads from a user machine to the web server. MultiPowUpload is a Macromedia Flash movie supported by most browsers and needs just Flash player plug-in on users side and any standard file upload script on server side.

    In a pure-HTML solution, client files can be uploaded to the server via a multipart/form-data form with one or more <INPUT TYPE=FILE> items on it. However, the form-based approach has the following limitation:

    • The "Choose File" dialog shown by a browser does not allow multiple selections.
    • To upload multiple files at once, the HTML form must contain multiple <INPUT TYPE=FILE> boxes, and each file must be selected individually.
    • An entire folder cannot be selected for uploading.
    • There is no way to specify file filters to be displayed in the Files of Type box of the "Choose File" dialog.
    • There is no way to put a limit on the type, size and number of files being uploaded before an upload begins.
    • File date information cannot be preserved.
    • There is no progress state information while upload.

    MultiPowUpload features:

    • Multiple file selection at once by Ctrl or Shift keys.
    • Selection the all files of the folder by Ctrl+A hot key.
    • Rich progress and status information during the upload process.
    • File filters by extension in the "Choose Files" dialog.
    • Limit the maximum allowed size of individual files.
    • Limit the maximum allowed total size of files.
    • Limit the maximum allowed number of files to be uploaded at the same time.
    • Possibility to cancel an upload anytime.
    • Access to files date modified, date created, name, size and creator(Mac users) information.
    • Download multiple files feature.
    • Multilingual and customizable interface.
    • Interface can be replaced with custom HTML and Java Script code.
    • Supports SSL (HTTPS) and authentication.

    MultiPowUpload system requirements:

    Server's side:

    • Any OS and web server.
    • Standard script which receives files sent using RFC 1867 protocol on server side. MultiPowUpload compatible with most upload scripts and components. Built-in ASP, ASP.NET, PHP and Perl scripts examples are included.


     

    User's side:

    • Any OS.
    • The browser has to be RFC 1867 compatible in order to upload files. Most known browsers are RFC 1867 compatible.
    • Macromedia Flash Player 8 plug-in should be installed.


    ==============================================================================

     

    Server side upload script examples:

    Examples demonstartes server side file upload scripts. Most scripts using built-in classes and functions to get uploaded files.

    ASP upload script example


    ASP.NET (C Sharp syntax) upload script example


    ASP.NET (VB.NET syntax) upload script example

    2008年3月27日 上午 12:56
  • 你可以換個寫法試試,

     

    Code Snippet

    Dim uploadFile As HttpPostedFile = Request.Files(0)

    '存檔
    uploadFile.SaveAs(Server.MapPath("") & "\" & _
       Path.GetFileName(uploadFile.FileName))

     

     

    之前也做過一次用flash傳檔,
    不過flash不是我寫的.

    因此不知道flash用的物件名稱是甚麼.

    所以就直接用Request.Files(0)來取得上傳的資料中第一個檔案物件.

    或許你的情況只是因為flash中上傳檔案的欄位名稱不是File而已.

    2008年3月27日 上午 02:20
  • SWFUpload

    採用 JavaScript + Flash 進行上傳動作,功能強大、一應俱全,雖然每有 ASP.NET 現成的控制項可用,但是有提供使用 ASP.NET 的範例可以參考,是個值得推薦使用的套件!

    其功能有:

    - 可一次上傳多個檔案。
    - 支援 JavaScript 的 Callback 事件。
    - 可在檔案開始上傳前取得部分檔案資訊。
    - 可以透過 XHTML 與 CSS 客製化上傳的元件。
    - 可得知檔案上傳進度。
    - 上傳檔案不需要 PostBack,可以等上傳檔案完成後再 PostBack 出去。
    - 只要是 Flash 支援的 Browser 都可以用。
    - 就算 Flash 或 JavaScript 都無效的時候,也可以正常上傳。
    - 可以在「檔案上傳之前」就先判斷檔案大小,超過限制可以不進行上傳。
    - 可以在瀏覽檔案時篩選特定的檔案類型
    - 支援上傳檔案佇列功能,可以在還沒上傳檔案之前將新增要上傳的檔案或移除要上傳的檔案。

     

    2008年3月27日 上午 02:37
  • 可以了~
    改成 Request.Files(0) 就可以了
    感謝幫忙喔~~ ^_^


    另外..

    保哥大大,您說的 SWFUpload 之前好像不曉得是您還是小朱大大有提供過
    當時我就試過了,但是我的 JavaScript 功力不夠,so....

    cmf大大,MultiPowUpload control 是個好東西,我會考慮考慮
    不過如果要用的話,我會需要原始 .fla 檔,因為要客制化~ so... 呵~~

     


    感謝大家熱心的幫忙~謝謝~~  ^_^
    問題解決的感覺真好~~~~~~~~~

     

    2008年3月27日 上午 06:55