我一直在试图上传视频我走上的使用AWS SDK S3服务桶。
这是我从亚马逊的例子为S3上传了代码。 唯一的东西我在做不同的是:
- 不是创建一个新的水桶,但重用一个已经存在。
使用预定的URI,其中的图像是文件。
public void uploadToS3(View v) { AmazonS3Client s3Client = new AmazonS3Client(new BasicAWSCredentials( Constants.ACCESS_KEY_ID, Constants.SECRET_KEY)); String[] filePathColumn = { MediaStore.Images.Media.DATA }; Cursor cursor = getContentResolver().query(fileUri, filePathColumn, null, null, null); cursor.moveToFirst(); int columnIndex = cursor.getColumnIndex(filePathColumn[0]); String filePath = cursor.getString(columnIndex); cursor.close(); // Put the image data into S3. try { //s3Client.createBucket(Constants.getPictureBucket()); PutObjectRequest por = new PutObjectRequest( Constants.getPictureBucket(), Constants.PICTURE_NAME, new java.io.File(filePath)); // Content type is determined // by file extension. s3Client.putObject(por); } catch (Exception exception) { // displayAlert( "Upload Failure", exception.getMessage() ); } }
问题是,一旦我尝试创建AmazonS3Client
,应用程序崩溃与noClassFound
例外。
这里是我的logcat:
05-17 10:42:02.555: E/AndroidRuntime(20310): FATAL EXCEPTION: main
05-17 10:42:02.555: E/AndroidRuntime(20310): java.lang.IllegalStateException: Could not execute method of the activity
05-17 10:42:02.555: E/AndroidRuntime(20310): at android.view.View$1.onClick(View.java:2154)
05-17 10:42:02.555: E/AndroidRuntime(20310): at android.view.View.performClick(View.java:2538)
05-17 10:42:02.555: E/AndroidRuntime(20310): at android.view.View$PerformClick.run(View.java:9152)
05-17 10:42:02.555: E/AndroidRuntime(20310): at android.os.Handler.handleCallback(Handler.java:587)
05-17 10:42:02.555: E/AndroidRuntime(20310): at android.os.Handler.dispatchMessage(Handler.java:92)
05-17 10:42:02.555: E/AndroidRuntime(20310): at android.os.Looper.loop(Looper.java:123)
05-17 10:42:02.555: E/AndroidRuntime(20310): at android.app.ActivityThread.main(ActivityThread.java:3691)
05-17 10:42:02.555: E/AndroidRuntime(20310): at java.lang.reflect.Method.invokeNative(Native Method)
05-17 10:42:02.555: E/AndroidRuntime(20310): at java.lang.reflect.Method.invoke(Method.java:507)
05-17 10:42:02.555: E/AndroidRuntime(20310): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:847)
05-17 10:42:02.555: E/AndroidRuntime(20310): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
05-17 10:42:02.555: E/AndroidRuntime(20310): at dalvik.system.NativeStart.main(Native Method)
05-17 10:42:02.555: E/AndroidRuntime(20310): Caused by: java.lang.reflect.InvocationTargetException
05-17 10:42:02.555: E/AndroidRuntime(20310): at java.lang.reflect.Method.invokeNative(Native Method)
05-17 10:42:02.555: E/AndroidRuntime(20310): at java.lang.reflect.Method.invoke(Method.java:507)
05-17 10:42:02.555: E/AndroidRuntime(20310): at android.view.View$1.onClick(View.java:2149)
05-17 10:42:02.555: E/AndroidRuntime(20310): ... 11 more
05-17 10:42:02.555: E/AndroidRuntime(20310): Caused by: java.lang.NoClassDefFoundError: com.amazonaws.services.s3.AmazonS3Client
05-17 10:42:02.555: E/AndroidRuntime(20310): at com.thepoosh.aws.s3upload.android.CameraToAmazonaws3Activity.uploadToS3(CameraToAmazonaws3Activity.java:63)
05-17 10:42:02.555: E/AndroidRuntime(20310): ... 14 more
05-17 10:42:02.555: E/AndroidRuntime(20310): Caused by: java.lang.ClassNotFoundException: com.amazonaws.services.s3.AmazonS3Client in loader dalvik.system.PathClassLoader[/data/app/com.thepoosh.aws.s3upload.android-1.apk]
05-17 10:42:02.555: E/AndroidRuntime(20310): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
05-17 10:42:02.555: E/AndroidRuntime(20310): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
05-17 10:42:02.555: E/AndroidRuntime(20310): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
05-17 10:42:02.555: E/AndroidRuntime(20310): ... 15 more