Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/269.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#web服务和数据库中图像的url将我的图像文件从android应用程序存储到服务器图像文件夹_C#_Android_Web Services - Fatal编程技术网

我想使用c#web服务和数据库中图像的url将我的图像文件从android应用程序存储到服务器图像文件夹

我想使用c#web服务和数据库中图像的url将我的图像文件从android应用程序存储到服务器图像文件夹,c#,android,web-services,C#,Android,Web Services,在这段android代码中,我将图像字符串值发送到web服务,以将图像存储在服务器上载文件夹中,并将图像的URL存储在数据库中: @Override protected Map<String, String> getParams() { Map<String, String> map = new HashMap<String, String>(); map.put("ProImage", encodedI

在这段android代码中,我将图像字符串值发送到web服务,以将图像存储在服务器上载文件夹中,并将图像的URL存储在数据库中:

@Override
      protected Map<String, String> getParams() {

          Map<String, String> map = new HashMap<String, String>();

          map.put("ProImage", encodedImage);

          return map;

      }
};
在我的web服务上,我正在传递字符串图像,然后将其转换为流位图,然后将其保存在上载文件夹中:

[WebMethod]
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]

//image
public void image(String ProImage)
{
    HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*");
    if (HttpContext.Current.Request.HttpMethod == "OPTIONS")
    {
        //These headers are handling the "pre-flight" OPTIONS call sent by the browser
        HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE");
        HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept");
        HttpContext.Current.Response.AddHeader("Access-Control-Max-Age", "1728000");
        HttpContext.Current.Response.End();
    }

    String resultJSON = "";

    JavaScriptSerializer js = new JavaScriptSerializer();
    JavaScriptSerializer serializer = new JavaScriptSerializer();
    int i = 0;
    try
    {
        //Context.Response.Clear();
        //Context.Response.ContentType = "application/json";
        //SqlConnection con = new SqlConnection("workstation id=mylibDB.mssql.somee.com;packet size=4096;user id=mihir893_SQLLogin_1;pwd=pddnvbsbzg;data source=mylibDB.mssql.somee.com;persist security info=False;initial catalog=mylibDB");
        byte[] bytes = Convert.FromBase64String(ProImage);

        System.IO.MemoryStream streamBitmap = new System.IO.MemoryStream(bytes);

        Bitmap bitImage = new Bitmap((Bitmap)System.Drawing.Image.FromStream(streamBitmap));

        System.Drawing.Image hh = System.Drawing.Image.FromStream(streamBitmap);

        String strFileName = "../Upload/myfile";// my E drive folder UploadFile

        //hh.Save(Server.MapPath(strFileName));
        hh.Save(strFileName, System.Drawing.Imaging.ImageFormat.Png);

        conn.Open();
        cmd = new SqlCommand("insert into image (image) values ('" + strFileName + "')", conn);

        // cmd.Parameters.AddWithValue("@Productname", email);

        //cmd.Parameters.AddWithValue("@Images", strFileName);
        i = cmd.ExecuteNonQuery();

        conn.Close();

    }

    catch (Exception ex)
    {
        resultJSON = ex.Message.ToString();
    }

    string status;
    if (i > 0)
    {
        status = "success";
    }

    else
    {
        status = "failed";
    }


    // resultJSON = serializer.Serialize(tableRows).ToString();
    JavaScriptSerializer js1 = new JavaScriptSerializer();
    string strJSON = js1.Serialize(status);
    // dtmkrs.Dispose();
    Context.Response.Clear();
    Context.Response.ContentType = "application/json";
    Context.Response.Flush();
    Context.Response.Write(strJSON);


}
要存储图像的文件夹:


欢迎来到Stack Overflow,请花点时间了解一下这里的情况(以及您的第一个徽章),阅读“如何”并进行检查,以增加获得反馈和有用答案的机会。欢迎来到Stack Overflow,请花点时间了解一下这里的情况(也是为了赢得你的第一枚徽章),阅读“如何”并进行检查,以增加获得反馈和有用答案的机会。
[WebMethod]
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]

//image
public void image(String ProImage)
{
    HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*");
    if (HttpContext.Current.Request.HttpMethod == "OPTIONS")
    {
        //These headers are handling the "pre-flight" OPTIONS call sent by the browser
        HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE");
        HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept");
        HttpContext.Current.Response.AddHeader("Access-Control-Max-Age", "1728000");
        HttpContext.Current.Response.End();
    }

    String resultJSON = "";

    JavaScriptSerializer js = new JavaScriptSerializer();
    JavaScriptSerializer serializer = new JavaScriptSerializer();
    int i = 0;
    try
    {
        //Context.Response.Clear();
        //Context.Response.ContentType = "application/json";
        //SqlConnection con = new SqlConnection("workstation id=mylibDB.mssql.somee.com;packet size=4096;user id=mihir893_SQLLogin_1;pwd=pddnvbsbzg;data source=mylibDB.mssql.somee.com;persist security info=False;initial catalog=mylibDB");
        byte[] bytes = Convert.FromBase64String(ProImage);

        System.IO.MemoryStream streamBitmap = new System.IO.MemoryStream(bytes);

        Bitmap bitImage = new Bitmap((Bitmap)System.Drawing.Image.FromStream(streamBitmap));

        System.Drawing.Image hh = System.Drawing.Image.FromStream(streamBitmap);

        String strFileName = "../Upload/myfile";// my E drive folder UploadFile

        //hh.Save(Server.MapPath(strFileName));
        hh.Save(strFileName, System.Drawing.Imaging.ImageFormat.Png);

        conn.Open();
        cmd = new SqlCommand("insert into image (image) values ('" + strFileName + "')", conn);

        // cmd.Parameters.AddWithValue("@Productname", email);

        //cmd.Parameters.AddWithValue("@Images", strFileName);
        i = cmd.ExecuteNonQuery();

        conn.Close();

    }

    catch (Exception ex)
    {
        resultJSON = ex.Message.ToString();
    }

    string status;
    if (i > 0)
    {
        status = "success";
    }

    else
    {
        status = "failed";
    }


    // resultJSON = serializer.Serialize(tableRows).ToString();
    JavaScriptSerializer js1 = new JavaScriptSerializer();
    string strJSON = js1.Serialize(status);
    // dtmkrs.Dispose();
    Context.Response.Clear();
    Context.Response.ContentType = "application/json";
    Context.Response.Flush();
    Context.Response.Write(strJSON);


}