无法打开从Android应用程序向wcf服务发送视频/音频文件

无法打开从Android应用程序向wcf服务发送视频/音频文件,android,wcf,file-upload,video-streaming,Android,Wcf,File Upload,Video Streaming,我尝试将视频文件从android发送到wcf服务。视频文件上传成功,两端大小相同,但问题是无法打开。对于其他文件,它可以正常工作,但不仅仅是视频文件 下面是我的Android代码: package com.example.filedemo; import java.io.File; import java.io.IOException; import java.io.UnsupportedEncodingException; import org.apache.http.Http

我尝试将视频文件从android发送到wcf服务。视频文件上传成功,两端大小相同,但问题是无法打开。对于其他文件,它可以正常工作,但不仅仅是视频文件

下面是我的Android代码:

      package com.example.filedemo;

import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;

import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.HttpMultipartMode;
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.entity.mime.content.StringBody;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONException;
import org.json.JSONObject;

import android.os.Environment;
import android.util.Log;

public class HttpUpload {

    public static String res;
    public static String response;
    public void myUploadedfile() {
        HttpClient httpClient = new DefaultHttpClient();

        HttpPost postRequest = new HttpPost(
                "http://10.160.0.18:85/Service.svc/UploadFile?fileName=vd.mp4");
        /* ResponseHandler<String> responseHandler = new BasicResponseHandler(); */

        // Indicate that this information comes in parts (text and file)
        MultipartEntity reqEntity = new MultipartEntity(
                HttpMultipartMode.BROWSER_COMPATIBLE);

        try {

            // Create a JSON object to be used in the StringBody
            JSONObject jsonObj = new JSONObject();

            // Add some values
            jsonObj.put("filename", "vd.mp4");

            // Add the JSON "part"
            reqEntity.addPart("entity", new StringBody(jsonObj.toString()));
        } catch (JSONException e) {
            Log.v("App", e.getMessage());
        } catch (UnsupportedEncodingException e) {
            Log.v("App", e.getMessage());
        }

        FileBody fileBody = new FileBody(new File(
                Environment.getExternalStorageDirectory(), "vd.mp4"));// ,"application/octet-stream");
        reqEntity.addPart("file", fileBody);

        try {
            postRequest.setEntity(reqEntity);

            // Execute the request "POST"
            HttpResponse httpResp = httpClient.execute(postRequest);

            /*HttpResponse response = null;*/
            // Check the status code, in this case "created"

            Log.v("App", "Created");
            /*if (((HttpResponse) response).getStatusLine().getStatusCode() == HttpStatus.SC_CREATED)
            {

            }*/
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


}

似乎问题在于MIME类型。

尝试使用此处接受答案中为uploadVideo()方法提供的代码。

    FileStream fileToupload = new FileStream("D:\\vd.mp4", FileMode.Create, FileAccess.Write);

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

fileToupload.Write(bytearray, 0, bytearray.Length);
fileToupload.Close();
fileToupload.Dispose();
return "success";