Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WCF服务无法从Ionic应用程序保存图像_C#_Angularjs_Wcf_Ionic Framework_File Transfer - Fatal编程技术网

C# WCF服务无法从Ionic应用程序保存图像

C# WCF服务无法从Ionic应用程序保存图像,c#,angularjs,wcf,ionic-framework,file-transfer,C#,Angularjs,Wcf,Ionic Framework,File Transfer,我正在开发一个应用程序并将图像上传到我的WCF服务中,问题是当图像来自我的WCF代码时,没有正确保存。将其另存为无效图像 [OperationContract] [WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "upload2/{fileName}")] string Upload2(string f

我正在开发一个应用程序并将图像上传到我的WCF服务中,问题是当图像来自我的WCF代码时,没有正确保存。将其另存为无效图像

[OperationContract]
[WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "upload2/{fileName}")]
string Upload2(string fileName, Stream fileStream);

public string Upload2(string fileName, Stream fileStream)
    {

        try
        {
            FileStream fileToupload = new FileStream(WebConfigurationManager.AppSettings["FilePath"] + fileName, FileMode.Create);

            byte[] bytearray = new byte[10000];
            int bytesRead, totalBytesRead = 0;
            do
            {
                bytesRead = fileStream.Read(bytearray, 0, bytearray.Length);
                totalBytesRead += bytesRead;
            } while (bytesRead > 0);

            fileToupload.Write(bytearray, 0, bytearray.Length);
            fileToupload.Close();
            fileToupload.Dispose();
            return "succ";
        }
        catch (Exception ex)
        {
            return ex.Message + " - " + ex.InnerException;
        }
    }
代码控制器AngularJs

$scope.subirFoto = function() {
    var options = new FileUploadOptions();

    options.fileKey = "post";

    options.fileName = imageURI.substr(imageURI.lastIndexOf('/')+1);
    options.mimeType = "image/jpeg";
    options.chunkedMode = false;


    var ft = new FileTransfer();

    ft.upload(imageURI, encodeURI("http://192.68.1.182:8085/IServiceTopStore.svc/upload2/"+options.fileName), win, fail, options);
}

如果有人需要,请解决它

[OperationContract]
[WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "UploadImage/{fileName}")]
string UploadImage(string fileName);

public string UploadImage(string fileName)
    {
        try
        {
            HttpPostedFile file = HttpContext.Current.Request.Files["post"];
            if (file == null)
                return null;
            string targetFilePath = WebConfigurationManager.AppSettings["FilePath"] + fileName;
            file.SaveAs(targetFilePath);
            return "succ   " + file.FileName.ToString(); ;
        }
        catch (Exception ex)
        {
            return ex.Message + " - " + ex.InnerException;
        }
    }
离子型:

$scope.subirFoto = function() {
    var options = new FileUploadOptions();

    options.fileKey = "post";

    options.fileName = imageURI.substr(imageURI.lastIndexOf('/')+1);
    options.mimeType = "image/jpeg";
    options.chunkedMode = false;


    var ft = new FileTransfer();

    ft.upload(imageURI, encodeURI("http://192.1.1.1:8085/IServiceTopStore.svc/upload2/"+options.fileName), win, fail, options);
}

如果有人需要,请解决它

[OperationContract]
[WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "UploadImage/{fileName}")]
string UploadImage(string fileName);

public string UploadImage(string fileName)
    {
        try
        {
            HttpPostedFile file = HttpContext.Current.Request.Files["post"];
            if (file == null)
                return null;
            string targetFilePath = WebConfigurationManager.AppSettings["FilePath"] + fileName;
            file.SaveAs(targetFilePath);
            return "succ   " + file.FileName.ToString(); ;
        }
        catch (Exception ex)
        {
            return ex.Message + " - " + ex.InnerException;
        }
    }
离子型:

$scope.subirFoto = function() {
    var options = new FileUploadOptions();

    options.fileKey = "post";

    options.fileName = imageURI.substr(imageURI.lastIndexOf('/')+1);
    options.mimeType = "image/jpeg";
    options.chunkedMode = false;


    var ft = new FileTransfer();

    ft.upload(imageURI, encodeURI("http://192.1.1.1:8085/IServiceTopStore.svc/upload2/"+options.fileName), win, fail, options);
}