Phonegap文件上传和aspx c#有什么例子吗?

本文关键字:什么 文件 aspx Phonegap | 更新日期: 2023-09-27 18:17:18

我被phonegap和fileupload卡住了。我只是试图使用phonegap API中的代码向服务器发送照片。

  function uploadPhoto(imageURI) {
        var options = new FileUploadOptions();
        options.fileKey="file";
        options.fileName=imageURI.substr(imageURI.lastIndexOf('/')+1);
        options.mimeType="image/jpeg";
        var params = new Object();
        params.value1 = "test";
        params.value2 = "param";
        options.params = params;
        var ft = new FileTransfer();
        ft.upload(imageURI, "http://some.server.com/upload.php", win, fail, options);
    }
    function win(r) {
        console.log("Code = " + r.responseCode);
        console.log("Response = " + r.response);
        console.log("Sent = " + r.bytesSent);
    }

我把我的测试aspx服务器放在它说upload.php的那行。

在这一点上,我意识到我不知道我在做什么。有没有人有用c#在aspx中接收文件的例子?

(在任何人问我之前,我确实有一些代码在我的aspx,但我意识到这可能是无稽之谈)

TIA

Phonegap文件上传和aspx c#有什么例子吗?

我已经为那些为这个问题而挣扎的人找到了答案。

ASP:

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form2" runat="server" enctype="multipart/form-data">
</form>
</body>
</html>
c#:

    string[] arr1;
    int loop1;
    HttpFileCollection Files;
    String TempFileName;
    HttpFileCollection MyFileCollection = Request.Files;
    Files = Request.Files; // Load File collection into HttpFileCollection variable.
    arr1 = Files.AllKeys;  // This will get names of all files into a string array.
    for (loop1 = 0; loop1 < arr1.Length; loop1++)
    {
        Response.Write("File: " + Server.HtmlEncode(arr1[loop1]) + "<br />");
        Response.Write("  size = " + Files[loop1].ContentLength + "<br />");
        Response.Write("  content type = " + Files[loop1].ContentType + "<br />");
        //TempFileName = "C:''TempFiles''File_" + loop1.ToString();
        TempFileName = Server.MapPath("~/") + "File_" + loop1.ToString();
        // Save the file.
        try
        {
            MyFileCollection[loop1].SaveAs(TempFileName);
        }
        catch (Exception ex)
        {
            Response.Write(" Write File Exception = " + ex + "<br />");
        }
        finally
        {
            Response.Write("Finally = No Exception" + "<br />");
        }

响应。写是返回到phonegap的。