Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/200.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
将图像从Android上载到asp.net_Android_Wcf_File Upload - Fatal编程技术网

将图像从Android上载到asp.net

将图像从Android上载到asp.net,android,wcf,file-upload,Android,Wcf,File Upload,我得到以下错误: Cannot process the message because the content type 'multipart/form-data; boundary=0JxmnFLOmjvutAKrtR1bmPCqpG8M6WbwE-aAvh8' was not the expected type 'text/xml; charset=utf-8' Android代码: HttpPost httppost = new HttpPost("http://192

我得到以下错误:

Cannot process the message because the content type
'multipart/form-data;
boundary=0JxmnFLOmjvutAKrtR1bmPCqpG8M6WbwE-aAvh8' was not the expected
type 'text/xml; charset=utf-8'

Android代码:

        HttpPost httppost = new HttpPost("http://192.168.9.103/AndroidService/MediaUploadService.svc/uploadFile1");
        File photo = new File(Environment.getExternalStorageDirectory(), "01.jpg");
        MultipartEntity t = new MultipartEntity();
        t.addPart("t", new FileBody(photo));
        httppost.setEntity(t);
        HttpClient httpclient = new DefaultHttpClient();
        HttpResponse response = httpclient.execute(httppost);
public class MediaUploadService : IMediaUploadService
{
    public void UploadFile(Stream fileContents)
    {
        byte[] buffer = new byte[10000];
        int bytesRead, totalBytesRead = 0;
        do
        {
            bytesRead = fileContents.Read(buffer, 0, buffer.Length);
            totalBytesRead += bytesRead;
        } while (bytesRead > 0);
        File.WriteAllText(@"D:\\Vechile\log2.txt", totalBytesRead.ToString());
    }
}
WCF代码:

        HttpPost httppost = new HttpPost("http://192.168.9.103/AndroidService/MediaUploadService.svc/uploadFile1");
        File photo = new File(Environment.getExternalStorageDirectory(), "01.jpg");
        MultipartEntity t = new MultipartEntity();
        t.addPart("t", new FileBody(photo));
        httppost.setEntity(t);
        HttpClient httpclient = new DefaultHttpClient();
        HttpResponse response = httpclient.execute(httppost);
public class MediaUploadService : IMediaUploadService
{
    public void UploadFile(Stream fileContents)
    {
        byte[] buffer = new byte[10000];
        int bytesRead, totalBytesRead = 0;
        do
        {
            bytesRead = fileContents.Read(buffer, 0, buffer.Length);
            totalBytesRead += bytesRead;
        } while (bytesRead > 0);
        File.WriteAllText(@"D:\\Vechile\log2.txt", totalBytesRead.ToString());
    }
}
有人能帮我做这个过程吗

我的问题:-
需要将图像文件从Android上传到服务器(通过IIS->.asp、.asmx、.svc等)


有人能就这个问题向我提出建议吗?

您可以向url发送两个参数:

  • fileName=文件名
  • fileContent=以base64编码的文件内容
在asp文件中,只需获取2个参数的内容,进行base64解码,然后将其写入名为filename参数的文件中