1

もう一度書いています。ユーザーが画像をクリックして画像をSDカードに保存し、画像ビューから画像を選択してサーバーに送信するアプリを開発しています。画像をバイト配列に変換してからBase64文字列形式でエンコードしましたが、その画像をサーバーに送信しようとすると、soap障害のエラーが発生します。これが私のAndroidデバイスのコードです:

public void doneImage(){

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    bitmap.compress(CompressFormat.JPEG, 100, out);
    byte[] imagebyte = out.toByteArray();

    String jp = caption.getText().toString();//for fetching the path of selected image path.//

    SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
    String strBase64 =  Base64.encode(imagebyte);

    PropertyInfo addProp = new PropertyInfo();
    addProp.setName("imgdata");
    addProp.setValue(strBase64);
    addProp.setType(String.class);
    Request.addProperty(addProp);


    PropertyInfo addProp1 = new PropertyInfo();
    addProp1.setName("FileName");
    addProp1.setValue(jp);
    addProp1.setType(String.class);
    Request.addProperty(addProp1);


    SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    soapEnvelope.dotNet=true;
    soapEnvelope.setOutputSoapObject(Request);

    HttpTransportSE aht=new HttpTransportSE(URL);

      try
       {
        aht.call(SOAP_ACTION, soapEnvelope);
        SoapPrimitive response = (SoapPrimitive)soapEnvelope.getResponse();
        Toast.makeText(getApplicationContext(), "Success" +response, Toast.LENGTH_LONG).show();
       }
      catch (Exception e) {
            if (dialog.isShowing())
                dialog.dismiss();
                dialog.cancel();
            Toast.makeText(getApplicationContext(),
                    e.toString(),
                    Toast.LENGTH_LONG).show();
            caption.setText(e.toString());
            //return null;
            //Log.e(e.getClass().getName(), e.getMessage(), e);

        }
} 




   @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

      switch (requestCode) {
     case PICK_IMAGE:
    if (resultCode == Activity.RESULT_OK) {
       Uri selectedImageUri = data.getData();

       String filePath = null;

      try {
       // OI FILE Manager
       String filemanagerstring = selectedImageUri.getPath();

       // MEDIA GALLERY
        String selectedImagePath = getPath(selectedImageUri);

        if (selectedImagePath != null) {
        filePath = selectedImagePath;

        caption.setText(selectedImagePath);

         } else if (filemanagerstring != null) {
        filePath = filemanagerstring;

        caption.setText(filemanagerstring);
            } else {
            Toast.makeText(getApplicationContext(), "Unknown path",
                            Toast.LENGTH_LONG).show();
            Log.e("Bitmap", "Unknown path");
               }

    if (filePath != null) {
       decodeFile(filePath);
     } else {
        bitmap = null;
        }
    } catch (Exception e) {
         Toast.makeText(getApplicationContext(), "Internal error",
                        Toast.LENGTH_LONG).show();
         Log.e(e.getClass().getName(), e.getMessage(), e);
        }
        }
        break;
    default:
    }
}

そしてサーバー側ではvb.netWebサービスを使用しました。そしてコードは次のとおりです。

_パブリック関数UploadImage(ByVal imgdata As String、ByVal FileName As String)As Integer

    'Find the path on the server of our apps images folder
    Dim FilePath As String = Server.MapPath("images")

    'strip the path and .jpg etc out of our filename
    Dim i As Integer = InStrRev(FileName, "\")
    FileName = Mid(FileName, i)
    Dim j As Integer = InStr(FileName, ".") - 1
    Dim k As Integer = Len(FileName)
    FileName = Mid(FileName, 1, j)

    'Storing an image to bitmap after converting from base64 format'
    Dim Bm As New System.Drawing.Bitmap(Base64ToImage(imgdata))

    'Convert the bitmap to a png and save it in our images folder
    BM.Save(FilePath & FileName, Imaging.ImageFormat.Jpeg)

    'eventually we will create a database entry for this image and return the image ID
    Return 1
End Function

'For converting the base64 satring value into the image'
Public Function Base64ToImage(ByVal base64String As String) As Image
    ' Convert Base64 String to byte[]
    Dim imageBytes As Byte() = Convert.FromBase64String(base64String)
    Dim ms As New MemoryStream(imageBytes, 0, imageBytes.Length)

    ' Convert byte[] to Image
    ms.Write(imageBytes, 0, imageBytes.Length)
    Dim image__1 As Image = Image.FromStream(ms, True)
    Return image__1
End Function

みんな助けてください-私は過去4日間からそれに取り組んでいます。どんな助けでもありがたいです。そして、よろしくお願いします......

4

1 に答える 1

1

Androidからサービスを呼び出す場合は、残りのほうがよいでしょう。とにかく、これを自分のやり方でやりたい場合は、ストリームをサービスに送信して、ストリームを取るメソッドを作成してください。あなたのアンドロイドエンドは出力ストリームの接続を要求し、それにすべてのバイトを書き込みます。

私はこれをRestful wcfで行いました。参考までに : MS Word ファイルを Android から .Net WCF にアップロードしますか?

于 2012-04-19T13:28:58.963 に答える