I'm making an Android Application
and trying to store files, e.g. docx, music, photos, videos in OpenStack
object storage(Swift) using it's API.But I'm having a problem in storing these files. From the API that I got, it only stores the name of the file but the object itself is missing when i try to download it from the dashboard.
The API I got from OpenStack
Documentations is this.
Method: PUT Link: (mylink)/v1/AUTH_(account)/(container)/(object)
HEADER Content-type: (required) X-Auth-Token: (required) Content-Length: (optional) ETag:(optional) Content-Disposition: (optional) Content-Encoding: (optional) X-Delete-At: (optional) X-Object-Meta-PIN: X-Delete-After: X-Object-Meta
BODY None
The first file that I tried to upload is a photo, I tried sending it as binary(base64) because base also in the API it only accepts strings. I'm not sure where to put it, so I tried pushing it in Content-Disposition but it failed. I'm not sure where else can i put the photo on the limited data that can be accepted by openstack.
Please help. I want to view the file that I have uploaded from phone and download it from dashboard.
This is my code:
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();
}