Skip to content

Commit

Permalink
Making changes to record filename
Browse files Browse the repository at this point in the history
  • Loading branch information
ikai committed Nov 25, 2010
1 parent 38028bc commit 34de6d1
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/com/android/photoshare/Main.java
Expand Up @@ -20,8 +20,10 @@
import android.app.Activity; import android.app.Activity;
import android.content.ContentResolver; import android.content.ContentResolver;
import android.content.Intent; import android.content.Intent;
import android.database.Cursor;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.provider.MediaStore;
import android.util.Log; import android.util.Log;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
Expand Down Expand Up @@ -73,15 +75,16 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
Uri selectedImage = data.getData(); Uri selectedImage = data.getData();
text.setText(selectedImage.toString()); text.setText(selectedImage.toString());
image.setImageURI(selectedImage); image.setImageURI(selectedImage);

String filename = getFilenameFromURI(selectedImage);
uploadImage(selectedImage);
uploadImage(selectedImage, filename);
} }
} }


// Need mime4j // Need mime4j
// http://james.apache.org/download.cgi#Apache_Mime4J // http://james.apache.org/download.cgi#Apache_Mime4J
// http://blog.tacticalnuclearstrike.com/2010/01/using-multipartentity-in-android-applications/ // http://blog.tacticalnuclearstrike.com/2010/01/using-multipartentity-in-android-applications/
protected void uploadImage(Uri imageToUploadUri) { protected void uploadImage(Uri imageToUploadUri, String filename) {


text.setText(imageToUploadUri.getPath()); text.setText(imageToUploadUri.getPath());
Log.d("Main", "Upload image: " + imageToUploadUri.toString()); Log.d("Main", "Upload image: " + imageToUploadUri.toString());
Expand All @@ -95,7 +98,7 @@ protected void uploadImage(Uri imageToUploadUri) {
HttpPost httpPost = new HttpPost(uploadImageUrl); HttpPost httpPost = new HttpPost(uploadImageUrl);


MultipartEntity mpEntity = new MultipartEntity(); MultipartEntity mpEntity = new MultipartEntity();
mpEntity.addPart("file", new InputStreamBody(is, mimeType, "lolcat.jpg")); mpEntity.addPart("file", new InputStreamBody(is, mimeType, filename));


httpPost.setEntity(mpEntity); httpPost.setEntity(mpEntity);
HttpResponse response = httpclient.execute(httpPost); HttpResponse response = httpclient.execute(httpPost);
Expand Down Expand Up @@ -145,5 +148,15 @@ protected String getUploadUrl(String getBlobstoreUrl) {
} }
return uploadUrl; return uploadUrl;
} }

// Taken from here:
// http://stackoverflow.com/questions/3401579/android-get-filename-and-path-from-uri-from-mediastore
public String getFilenameFromURI(Uri contentUri) {
String[] proj = { MediaStore.Images.Media.DISPLAY_NAME };
Cursor cursor = managedQuery(contentUri, proj, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DISPLAY_NAME);
cursor.moveToFirst();
return cursor.getString(column_index);
}


} }

0 comments on commit 34de6d1

Please sign in to comment.