我正在尝试使用FakeS3测试AmazonS3 API。我已按照说明书的说法安装并启动它。当我运行代码时,服务器响应并且日志显示没有错误。存储桶在指定目录中创建。但是,该文件不在目录中。相反,还有另一个名为keyName的目录。此目录中没有文件。我做错了什么?
import java.io.File;
import com.amazonaws.AmazonClientException;
import com.amazonaws.AmazonServiceException;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.auth.profile.ProfileCredentialsProvider;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3Client;
import com.amazonaws.services.s3.S3ClientOptions;
import com.amazonaws.services.s3.model.PutObjectRequest;
public class FileUpload {
private static String bucketName = "bucket1";
private static String keyName = "File1";
private static String uploadFileName = "message.txt";
public static void main(String[] args){
//create a new AmazonS3Client object
BasicAWSCredentials credentials = new BasicAWSCredentials("foo", "bar");
AmazonS3 client = new AmazonS3Client(credentials);
client.setEndpoint("http://localhost:10000");
client.setS3ClientOptions(newS3ClientOptions().withPathStyleAccess(true));
System.out.println("Creating a new bucket......");
client.createBucket(bucketName); //create a new bucket
System.out.println("Uploading text file into specified bucket......");
File fin = new File(uploadFileName);
client.putObject(bucketName, keyName, fin);
System.out.println("Done");
}
}
服务器日志示例:
st - - [09/Jul/2015:19:10:56 CDT] "PUT /bucket1/ HTTP/1.1" 200 0
- -> /bucket1/
localhost - - [09/Jul/2015:19:10:56 CDT] "PUT /bucket1/File1 HTTP/1.1" 200 0
- -> /bucket1/File1