我一直在尝试使用 AWS SDK 将我拍摄的视频上传到 S3 服务桶。
这是我从 Amazon 示例中获取的用于 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