简体   繁体   English

Phonegap文件上传到asmx Web服务

[英]Phonegap file upload to the asmx web service

I'm trying to upload image file to the asmx web service from Android and ios device but i'm getting error which list of below: 我正在尝试将图像文件从Android和ios设备上传到asmx Web服务,但出现以下错误:

for Android: FileNotFoundException on the server Error on FileTransfer.upload Error on FileTransfer.execute IOException: Received error from server. 对于Android:服务器上的FileNotFoundException FileTransfer.upload上的错误FileTransfer.execute上的错误IOException:从服务器接收到错误。 "http_status":500, "code":1 “ http_status”:500,“代码”:1

for iOS: FileNotFoundException on the server Error on FileTransfer.upload Error on FileTransfer.execute IOException: Received error from server. 对于iOS:服务器上的FileNotFoundException FileTransfer.upload上的错误FileTransfer.execute上的错误IOException:从服务器接收到错误。 "http_status":500, "code":3 “ http_status”:500,“代码”:3

I'm using Icenium for development and service_url parameter of ft.upload() method is working i can call web service on browser but when i try to use in my project i got same error. 我正在使用Icenium进行开发,并且ft.upload()方法的service_url参数正在运行,我可以在浏览器上调用Web服务,但是当我尝试在我的项目中使用时,出现了同样的错误。

IIS logs below: IIS日志如下:

Software: Microsoft Internet Information Services 7.5 软体:Microsoft Internet Information Services 7.5

Version: 1.0 版本:1.0

Date: 2013-02-22 11:00:07 日期:2013-02-22 11:00:07

Fields: date time s-ip cs-method cs-uri-stem cs-uri-query s-port cs-username c-ip cs(User- Agent) sc-status sc-substatus sc-win32-status time-taken 字段:日期时间s-ip cs-method cs-uri-stem cs-uri-query s-port cs-username c-ip cs(User-Agent)sc-status sc-substatus sc-win32-status花费的时间

2013-02-22 11:00:07 192.168.1.103 POST /ExpenseService.asmx/UploadFile - 40201 - 78.189.173.183 Camera%20Sample%20Official/1.0+CFNetwork/609+Darwin/13.0.0 500 0 0 287 2013-02-22 11:01:28 192.168.1.103 POST /ExpenseService.asmx/UploadFile - 40201 - 78.189.173.183 Camera%20Sample%20Official/1.0+CFNetwork/609+Darwin/13.0.0 500 0 0 144

my cordova version 2.2.0. 我的cordova版本2.2.0。 Any ideas what i did wrong? 任何想法我做错了什么?

ASMX Service: ASMX服务:

#region FileUpload
    [WebMethod]
    //[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
    public string UploadFile()
    {
        try
        {
            File.WriteAllText(@"d:\test.txt", "hede");
            HttpPostedFile file = HttpContext.Current.Request.Files[0];
            if (file == null)
                return null;
            string targetFilePath = @"d:\" + file.FileName;
            file.SaveAs(targetFilePath);
            return file.FileName.ToString();
        }
        catch (Exception ex)
        {
            File.WriteAllText(@"d:\uploader.txt", ex.Message.ToString());
            return null;
        }

    }
    #endregion

Client Side: 客户端:

var options = new FileUploadOptions(); 
options.chunkedMode  = false;
options.fileKey = "ficheFile";
console.log('imageFileName: ' + imageFileName);    
options.fileName = imageFileName; 
options.mimeType="image/jpeg";
console.log('imageSrc: ' + imageSrc);

var ft = new FileTransfer(); 
ft.upload(imageSrc, encodeURI("http://mydomain:40201/ExpenseService.asmx/UploadFile"), win, fail, options); 

Here is my adb logcat: 这是我的adb logcat:

E/FileTransfer(11472): {"target":"http:\/\/mydomain:40201\/ExpenseService.asmx\/SaveFile","source":"file:\/\/\/mnt
\/sdcard\/Android\/data\/com.telerik.Camera_Sample_Official\/cache\/1361950930301.jpg","http_status":500,"code":1}
E/FileTransfer(11472): java.io.FileNotFoundException: http://78.189.173.183:40201/ExpenseService.asmx/SaveFile
E/FileTransfer(11472):  at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getInputStream(H
ttpURLConnectionImpl.java:521)
E/FileTransfer(11472):  at org.apache.cordova.FileTransfer.getInputStream(FileTransfer.java:480)
E/FileTransfer(11472):  at org.apache.cordova.FileTransfer.access$400(FileTransfer.java:62)
E/FileTransfer(11472):  at org.apache.cordova.FileTransfer$1.run(FileTransfer.java:402)
E/FileTransfer(11472):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
E/FileTransfer(11472):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
E/FileTransfer(11472):  at java.lang.Thread.run(Thread.java:1019)
D/CordovaLog(11472): Error Code: 1
D/CordovaLog(11472): : Line 1153648589 : Error Code: 1
I/Web Console(11472): Error Code: 1 at :1153648589

Kind Regards. 亲切的问候。

httpstaus 500 is a server error. httpstaus 500是服务器错误。 It seems that there's a bug in your UploadFile function. 看来您的UploadFile函数中存在错误。

You may attach w3wp.exe to process for testing your service 您可以将w3wp.exe附加到测试服务的过程中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM