【发布时间】:2014-06-28 15:13:09
【问题描述】:
在我的最后一个应用程序中,我将使用Koush Ion 库。它非常方便,但我在将文件上传到我的休息服务器时遇到了问题。 注意:我的服务器对成功上传过程的响应是 1
我喜欢这样的代码:
public class MainActivity extends Activity {
Button upload, login;
TextView uploadCount;
ProgressBar progressBar;
String token, FilePath;
Future<String> uploading;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
upload = (Button) findViewById(R.id.upload);
uploadCount = (TextView) findViewById(R.id.upload_count);
progressBar = (ProgressBar) findViewById(R.id.progress);
token = "147c85ce29dc585966271280d59899a02b94c020";
FilePath = Environment.getExternalStorageDirectory().toString()+"/police.mp3";
upload.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (uploading !=null && !uploading.isCancelled()){
resetUpload();
return;
}
upload.setText("Uploading...");
uploading = Ion.with(MainActivity.this)
.load("http://myserver.com/api/v1/tone/upload/?token="+token)
.setLogging("UPLOAD LOGS:", Log.DEBUG)
.uploadProgressBar(progressBar)
.uploadProgressHandler(new ProgressCallback() {
@Override
public void onProgress(int downloaded, int total) {
uploadCount.setText("" + downloaded + "/" + total);
}
})
.setMultipartParameter("title", "police")
.setMultipartParameter("category", "7")
.setMultipartFile("file_url", new File(FilePath))
.asString()
.setCallback( new FutureCallback<String>() {
@Override
public void onCompleted(Exception e, String result) {
// TODO Auto-generated method stub
}
})
;
}
});
但是我从服务器收到了 TimeoutException。我的问题是: 1.我做的文件选择方法对吗?! 2. 是否应该使用Future Callback as String?!
我通过 fiddler2 检查我对服务器的请求,当我尝试将文件上传到服务器时...它显示请求发送,multipartParameters 发送但是当尝试发送文件时...fiddler 显示错误:
Protocol Violation Report:
Content-Length mismatch: Request Header indicated 455 bytes, but client sent 387 bytes.
【问题讨论】:
-
什么版本的离子?你的服务器后端是什么?其他使用 ion 对服务器的 http 调用是否有效?
-
@koush 是最新的,是的,我可以进行 http 调用(我可以发送 json 对象并获取 json 对象作为结果).....请帮助我。非常感谢:)
-
嘿,你解决了这个问题吗?我有同样的事情
-
@Danpe 不,这是一个未解决的问题github.com/koush/ion/issues/362
标签: android file-upload android-asynctask ion-koush