gpt4 book ai didi

android - 视频上传安卓

转载 作者:太空狗 更新时间:2023-10-29 14:15:02 24 4
gpt4 key购买 nike

当我尝试上传大小大于 20MB 的视频时,服务器没有收到正在发送的任何参数。我正在将视频和 jsonobject 作为字符串发送到服务器。我正在使用 httpmime-4.1.1 jar。下面是我的代码。我是 android 开发的新手,任何帮助都将不胜感激。我需要快速解决方案。请帮助我

String s = json;
Log.d("message", "s==="+s);
HttpClient client = new DefaultHttpClient();
HttpConnectionParams.setConnectionTimeout(client.getParams(), 10000); // Timeout
StringBuilder sq = null; // Limit

String result = null;
String result1 = null;
try {
HttpPost post = new HttpPost(url);

MultipartEntity reqEntity = new MultipartEntity(
HttpMultipartMode.BROWSER_COMPATIBLE);



Log.d("message","video"+ bin.getFilename());

reqEntity.addPart("video",bin);



reqEntity.addPart("arguments", new StringBody(s.toString()));

post.setEntity(reqEntity);
int timeoutConnection = 60000;
HttpParams httpParameters = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParameters,
timeoutConnection);
int timeoutSocket = 60000;

HttpConnectionParams.setTcpNoDelay(httpParameters, true);

try {
HttpResponse response = client.execute(post);
Log.v("@WebSErvice:"+response, "Result0" + response);
if (response == null) {
result = null;
} else {

try {
TieWebServicesComponents BWSC = new TieWebServicesComponents(
TieWebServicesComponents.POST_TASK, mContext);
result = BWSC.inputStreamToString(response.getEntity()
.getContent());
Log.v("message:CommunityHome Response"+response, "Result1" + result);

} catch (IllegalStateException e) {
// Log.e(TAG, e.getLocalizedMessage(), e);

} catch (IOException e) {
// Log.e(TAG, e.getLocalizedMessage(), e);
}

}

}catch(NullPointerException ne){


}
}
catch(Exception e) {
e.printStackTrace();

}

//Log.v("@WebSErvice:", "REsult" + result);

最佳答案

我以前做过这个,我有最大 80mb 的轨道并使用 MultiPartEntity 上传试试下面的功能。

public class asyncUploadtrack extends AsyncTask<Void, Integer, Void>
{
HttpResponse response;
private android.app.ProgressDialog dialog;
long totalSize;

protected void onPostExecute(String result)
{

}
@Override
protected void onPreExecute()
{

}
@Override
protected void onProgressUpdate(Integer... values)
{

}
protected Void doInBackground(Void... params)
{
Log.i("Do in Backgtound", "Background");
String url =app.WEB_API_URL+"?op="+ Constant.METHOD_UPLOAD_TRACK;
File video = new File(trackPath); // path of file
Bitmap out = Constant.bitmapResize(TrackFragment.btmTrackImg,308, 296) ;//Bitmap.createScaledBitmap(TrackFragment.btmTrackImg, 408, 396,true);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
out.compress(CompressFormat.JPEG, 50, bos);
byte[] data = bos.toByteArray();


HttpClient httpclient = new DefaultHttpClient();
HttpPost post = new HttpPost(url);




try
{
MultipartEntity multipartEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
multipartEntity.addPart("music", new FileBody(video));
multipartEntity.addPart("title",new StringBody(trackTitle));
multipartEntity.addPart("user", new StringBody(app.preferences.getStringPref("userId")));


multipartEntity.addPart("filename", new StringBody("song.mp3"));
multipartEntity.addPart("avatar",new ByteArrayBody(data, "trackImage"));
//After adding everything we get the content's lenght
totalSize = multipartEntity.getContentLength();
post.setEntity(multipartEntity);
response = httpclient.execute(post);
try
{
Log.i("Response is",response.getStatusLine().toString());
}
catch (Exception e)
{
e.printStackTrace();
}
}
catch (IOException e)
{
e.printStackTrace();
}
return null;
}
}

关于android - 视频上传安卓,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23126147/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com