将图像文件发布到mediafire';s使用Android异步Http客户端上传资源
我正在尝试使用Android应用程序的upload API资源将文件上载到Mediafire。另外,我正在使用整个应用程序来处理其余的通话 问题:将图像文件发布到mediafire';s使用Android异步Http客户端上传资源,android,post,asynchronous,Android,Post,Asynchronous,我正在尝试使用Android应用程序的upload API资源将文件上载到Mediafire。另外,我正在使用整个应用程序来处理其余的通话 问题: 上载失败,因为Mediafire返回代码-99,“”。 我正在传递session_令牌以及包括图像文件在内的3个其他参数 这是电话留言: RequestParams upload_params = new RequestParams(); File myFile = new File(image.getPath()); try { uploa
上载失败,因为Mediafire返回代码-99,“”。
我正在传递session_令牌以及包括图像文件在内的3个其他参数 这是电话留言:
RequestParams upload_params = new RequestParams();
File myFile = new File(image.getPath());
try {
upload_params.put("filename", myFile);
} catch(FileNotFoundException e) {
}
upload_params.put("session_token", session_token);
upload_params.put("uploadkey", MyConstants.MEDIA_FOLDER_KEY);
upload_params.put("response_format", MyConstants.MEDIA_RESPONSE_FORMAT);
Log.d("PARAMS: ", upload_params.toString());
client.post(MyConstants.MEDIA_BASE_URL + MyConstants.MEDIA_UPLOAD, upload_params, new JsonHttpResponseHandler() {
@Override
public void onStart() {
}
@Override
public void onSuccess(int statusCode, Header[] headers, byte[] response) {
String response_string = new String(response);
Log.d("RESPONSE: ", response_string);
Log.d("SESSION_TOKEN: ", session_token);
Log.d("STATUS CODE: ", Integer.toString(statusCode));
for(int i = 0; i < headers.length; i++) {
Log.d("Header " + i + ": ", headers[i].toString());
}
}
@Override
public void onFailure(int statusCode, Header[] headers, byte[] errorResponse, Throwable e) {
}
});
RequestParams upload_params = new RequestParams();
File myFile = new File(image.getPath());
try {
upload_params.put("filename", myFile);
} catch(FileNotFoundException e) {
}
client.post(MyConstants.MEDIA_BASE_URL + MyConstants.MEDIA_UPLOAD +
"?session_token=my_session_token" +
"&uploadkey=" + MyConstants.MEDIA_FOLDER_KEY +
"&response_format=" + MyConstants.MEDIA_RESPONSE_FORMAT),
upload_params,
new JsonHttpResponseHandler() {
@Override
public void onStart() {
}
@Override
public void onSuccess(int statusCode, Header[] headers, byte[] response) {
Log.d("RESPONSE: ", new String(response));
Log.d("SESSION_TOKEN: ", session_token);
Log.d("STATUS CODE: ", Integer.toString(statusCode));
for(int i = 0; i < headers.length; i++) {
Log.d("Header " + i + ": ", headers[i].toString());
}
}
@Override
public void onFailure(int statusCode, Header[] headers, byte[] errorResponse, Throwable e) {
}
});
RequestParams upload_params=newrequestparams();
File myFile=新文件(image.getPath());
试一试{
上传参数put(“文件名”,myFile);
}catch(filenotfounde异常){
}
上传参数put(“会话令牌”,会话令牌);
upload_params.put(“uploadkey”,MyConstants.MEDIA文件夹_KEY);
上传参数put(“响应格式”,MyConstants.MEDIA\u响应格式);
Log.d(“PARAMS:,upload_PARAMS.toString());
client.post(MyConstants.MEDIA_BASE_URL+MyConstants.MEDIA_上传,上传参数,新的JsonHttpResponseHandler(){
@凌驾
public void onStart(){
}
@凌驾
成功时公共无效(int statusCode,头[]头,字节[]响应){
字符串响应\字符串=新字符串(响应);
Log.d(“响应:”,响应字符串);
Log.d(“会话令牌:”,会话令牌);
Log.d(“状态代码:”,Integer.toString(状态代码));
对于(int i=0;i
我不知道为什么,但我认为我的session\u令牌、uploadkey和response\u格式没有被发送,因为当我查看logcat时,我看到我从Mediafire返回的响应是XML格式的
任何帮助都将不胜感激!如果需要更多信息,请告诉我。因此,经过无数个小时的调试(3天的时间),我终于找到了上传失败的原因 基本上,Mediafire只需要文件作为POST参数。它需要会话令牌、uploadkey和其他参数作为GET 我将上传参数和POST请求更改为以下内容以使其正常工作:
RequestParams upload_params = new RequestParams();
File myFile = new File(image.getPath());
try {
upload_params.put("filename", myFile);
} catch(FileNotFoundException e) {
}
upload_params.put("session_token", session_token);
upload_params.put("uploadkey", MyConstants.MEDIA_FOLDER_KEY);
upload_params.put("response_format", MyConstants.MEDIA_RESPONSE_FORMAT);
Log.d("PARAMS: ", upload_params.toString());
client.post(MyConstants.MEDIA_BASE_URL + MyConstants.MEDIA_UPLOAD, upload_params, new JsonHttpResponseHandler() {
@Override
public void onStart() {
}
@Override
public void onSuccess(int statusCode, Header[] headers, byte[] response) {
String response_string = new String(response);
Log.d("RESPONSE: ", response_string);
Log.d("SESSION_TOKEN: ", session_token);
Log.d("STATUS CODE: ", Integer.toString(statusCode));
for(int i = 0; i < headers.length; i++) {
Log.d("Header " + i + ": ", headers[i].toString());
}
}
@Override
public void onFailure(int statusCode, Header[] headers, byte[] errorResponse, Throwable e) {
}
});
RequestParams upload_params = new RequestParams();
File myFile = new File(image.getPath());
try {
upload_params.put("filename", myFile);
} catch(FileNotFoundException e) {
}
client.post(MyConstants.MEDIA_BASE_URL + MyConstants.MEDIA_UPLOAD +
"?session_token=my_session_token" +
"&uploadkey=" + MyConstants.MEDIA_FOLDER_KEY +
"&response_format=" + MyConstants.MEDIA_RESPONSE_FORMAT),
upload_params,
new JsonHttpResponseHandler() {
@Override
public void onStart() {
}
@Override
public void onSuccess(int statusCode, Header[] headers, byte[] response) {
Log.d("RESPONSE: ", new String(response));
Log.d("SESSION_TOKEN: ", session_token);
Log.d("STATUS CODE: ", Integer.toString(statusCode));
for(int i = 0; i < headers.length; i++) {
Log.d("Header " + i + ": ", headers[i].toString());
}
}
@Override
public void onFailure(int statusCode, Header[] headers, byte[] errorResponse, Throwable e) {
}
});
RequestParams upload_params=newrequestparams();
File myFile=新文件(image.getPath());
试一试{
上传参数put(“文件名”,myFile);
}catch(filenotfounde异常){
}
client.post(MyConstants.MEDIA\u BASE\u URL+MyConstants.MEDIA\u上传+
“?会话\u令牌=我的会话\u令牌”+
“&uploadkey=“+MyConstants.MEDIA\u文件夹\u密钥”+
“&response_format=“+MyConstants.MEDIA_response_format”),
上传参数,
新的JsonHttpResponseHandler(){
@凌驾
public void onStart(){
}
@凌驾
成功时公共无效(int statusCode,头[]头,字节[]响应){
Log.d(“响应:”,新字符串(响应));
Log.d(“会话令牌:”,会话令牌);
Log.d(“状态代码:”,Integer.toString(状态代码));
对于(int i=0;i