0

あるページで見つけたこのコードを使用していますが、Androidアプリケーションからサーバーに画像をアップロードすることしかできず、機能していますが、ビデオ(.mp4)をアップロードすると、不明のように「ファイル」として保存されます。

public void upload() throws Exception {
    //Url of the server
    String url = "";
    HttpClient client = new DefaultHttpClient();
    HttpPost post = new HttpPost(url);
    MultipartEntity mpEntity = new MultipartEntity();
    //Path of the file to be uploaded
    String filepath = "";
    File file = new File(filepath);
    ContentBody cbFile = new FileBody(file);        

    //Add the data to the multipart entity
    mpEntity.addPart("image", cbFile);
    mpEntity.addPart("name", new StringBody("Test", Charset.forName("UTF-8")));
    mpEntity.addPart("data", new StringBody("This is test report", Charset.forName("UTF-8")));
    post.setEntity(mpEntity);
    //Execute the post request
    HttpResponse response1 = client.execute(post);
    //Get the response from the server
    HttpEntity resEntity = response1.getEntity();
    String Response=EntityUtils.toString(resEntity);
    Log.d("Response:", Response);
    //Generate the array from the response
    JSONArray jsonarray = new JSONArray("["+Response+"]");
    JSONObject jsonobject = jsonarray.getJSONObject(0);
    //Get the result variables from response 
    String result = (jsonobject.getString("result"));
    String msg = (jsonobject.getString("msg"));
    //Close the connection
    client.getConnectionManager().shutdown();
}

動画をアップロードするためにこれを機能させる方法はありますか?

4

1 に答える 1

0

このコードに問題はなく、動画や画像をアップロードしても問題なく動作します。問題は、名前にファイル拡張子が含まれていないことでした。そのため、動画がアップロードされたときは、NAME だけでなく NAME.EXTENSION である必要があります。

注:大きな(2MB-10GB)画像またはビデオをサーバーにアップロードしようとしているすべての人にとって、私が見つけた唯一の解決策は、ファイルをチャンクでエンコードし、各チャンクをサーバーにアップロードすることでした。そこからエンコードするだけです再びチャンク。サイズ制限なし:)!!!!

于 2013-02-14T17:59:07.130 に答える