私は Android アプリケーションを作成しており、OpenStack
その API を使用してオブジェクト ストレージ (Swift) に docx、音楽、写真、ビデオなどのファイルを保存しようとしていますが、これらのファイルの保存に問題があります。取得した API から、ファイルの名前のみが保存されますが、ダッシュボードからダウンロードしようとすると、オブジェクト自体が見つかりません。
OpenStack
Documentationsから取得した APIはこれです。
メソッド: PUT リンク: (mylink)/v1/AUTH_(アカウント)/(コンテナー)/(オブジェクト)
HEADER Content-type: (必須) X-Auth-Token: (必須) Content-Length: (オプション) ETag:(オプション) Content-Disposition: (オプション) Content-Encoding: (オプション) X-Delete-At: (オプション) X-Object-Meta-PIN: X-Delete-After: X-Object-Meta
本文 なし
アップロードしようとした最初のファイルは写真です。ベースもAPIで文字列のみを受け入れるため、バイナリ(base64)として送信してみました。どこに入れたらいいのかわからないので、Content-Disposition でプッシュしてみましたが失敗しました。openstackが受け入れることができる限られたデータに写真をどこに置くことができるかわかりません。
助けてください。電話からアップロードしたファイルを表示し、ダッシュボードからダウンロードしたいと考えています。
これは私のコードです:
HttpClient httpclient = new DefaultHttpClient();
HttpPut httpost = new HttpPut("mylink/v1/AUTH_fa6362c6520449f9a8905e84fee68f8c/photos/"+imagename);
try {
httpost.setHeader("X-Auth-Token", "nasbfdblfdfsdfsdfd123a");
httpost.setHeader("Content-Type", "application/octet-stream");
httpost.setHeader("Content-Length ", Integer.toString(binaryimagelength) );
httpost.setHeader("Content-Disposition ", binaryimage);// this is path of the image from the phone memory (e.g. )
Log.i("", "pushing your data");
HttpResponse response=httpclient.execute(httpost);
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String response2 = httpclient.execute(httpost, responseHandler);
Log.i("", "Response1: " + response.getStatusLine());
Log.i("", "Response2: " + response2);
}catch (IOException e) {
Log.e("", "IOException " + e.toString());
// TODO Auto-generated catch block
AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this,AlertDialog.THEME_DEVICE_DEFAULT_LIGHT).create();
alertDialog.setTitle("Error");
alertDialog.setMessage(e.toString());
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// TODO Add your code for the button here.
}
});
alertDialog.show();
}