2011-12-07 6 views
0

私はphonegapとfileuploadで立ち往生している。私は、phonegap APIのコードを使用してサーバーに写真を送信しようとしていました。Phonegap fileuploadとaspx c#android - 例がありますか?

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

+0

このコードを基本的なPHPスクリプトで実行して、phonegapアプリケーションが何かを返すかどうか確認しましたか? –

+0

@camilo_uこれは少し恥ずかしいですが、私はすべてのことについて私の頭を傷つけています。私はPHPを見たが、ほとんどの例はフォームに依存しているようだ。私はそれが動作するためにも私はPHPで受信する必要があるか分からない。また、私のwebhostは、コントロールパネルがtreacle atmのようなものであるため、ナットを運転しています。 –

答えて

0

私はこれで苦労している人のための答えを発見しました。

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 />"); 
     } 

response.writesは戻っPhoneGapのに来るものです。

関連する問題