本文整理汇总了Java中com.aliyun.openservices.oss.OSSClient类的典型用法代码示例。如果您正苦于以下问题:Java OSSClient类的具体用法?Java OSSClient怎么用?Java OSSClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
OSSClient类属于com.aliyun.openservices.oss包,在下文中一共展示了OSSClient类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: upload
import com.aliyun.openservices.oss.OSSClient; //导入依赖的package包/类
@Override
public void upload(String path, File file, String contentType) {
PluginConfig pluginConfig = getPluginConfig();
if (pluginConfig != null) {
String accessId = pluginConfig.getAttribute("accessId");
String accessKey = pluginConfig.getAttribute("accessKey");
String bucketName = pluginConfig.getAttribute("bucketName");
InputStream inputStream = null;
try {
inputStream = new FileInputStream(file);
OSSClient ossClient = new OSSClient(accessId, accessKey);
ObjectMetadata objectMetadata = new ObjectMetadata();
objectMetadata.setContentType(contentType);
objectMetadata.setContentLength(file.length());
ossClient.putObject(bucketName, StringUtils.removeStart(path, "/"), inputStream, objectMetadata);
} catch (Exception e) {
e.printStackTrace();
} finally {
IOUtils.closeQuietly(inputStream);
}
}
}
示例2: add
import com.aliyun.openservices.oss.OSSClient; //导入依赖的package包/类
@Override
public String add(InputStream input, String dir, String filename, long lenght, String contentType) throws IOException {
if (input == null) {
throw new NullPointerException("input不能为空.");
}
OSSClient client = new OSSClient(endpoint, accessKeyId, secretAccessKey);
// System.err.println("endpoint:" + endpoint);
ObjectMetadata meta = new ObjectMetadata();
meta.setContentLength(lenght);
if (contentType != null) {
meta.setContentType(contentType);
}
filename = toUuidFileName(filename);
String uri;
if (dir == null || dir.length() == 0) {
uri = filename;
}
else {
uri = dir + "/" + filename;
}
System.out.println("uri:" + uri + " lenght:" + lenght);
PutObjectResult result = client.putObject(bucketName, uri, input, meta);
System.out.println(result.getETag());
return "/" + uri;
}
示例3: save
import com.aliyun.openservices.oss.OSSClient; //导入依赖的package包/类
@SuppressWarnings("deprecation")
@Override
public String save(GenericFile genericFile){
OSSClient client = new OSSClient(accessKeyId, accessKeySecret);
if(!client.doesBucketExist(bucketName)){
client.createBucket(bucketName);
}
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentLength(genericFile.getLength());
if(fileNameGenerator == null){
throw new RuntimeException("no file name generator configed");
}
String path = fileNameGenerator.gen() + genericFile.getExtend();
client.putObject(bucketName, path, genericFile.getIs(), metadata);
return path;
}
示例4: getRootFolder
import com.aliyun.openservices.oss.OSSClient; //导入依赖的package包/类
public StorageFolder getRootFolder() {
if (root == null) {
StorageBucket bucket = bucketService.singleFileBucket();
OSSClient client = new OSSClient(bucket.getUploadUrl(), bucket.getAccessKeyId(),
bucket.getAccessKeySecret());
root = StorageFolder.getRootFolder(client, bucket.getName());
}
return root;
}
示例5: initialize
import com.aliyun.openservices.oss.OSSClient; //导入依赖的package包/类
@Override
public void initialize(URI uri, Configuration conf) throws IOException {
uri = checkNotNull(uri);
conf = checkNotNull(conf);
OSSCredentials ossCredentials = new OSSCredentials();
ossCredentials.initialize(uri, conf);
client = new OSSClient(ossCredentials.getAccessKeyId(), ossCredentials.getSecretAccessKey());
bucket = checkNotNull(uri.getHost(), "URI must include a host: %s", uri);
// TODO deal with server-side encryption for store, copy
multiPartUploader = new MultiPartUploader(client, bucket, conf);
}
示例6: MultiPartUploader
import com.aliyun.openservices.oss.OSSClient; //导入依赖的package包/类
MultiPartUploader(OSSClient client, String bucket, Configuration conf) {
this.client = checkNotNull(client);
this.bucket = checkNotNull(bucket);
checkNotNull(conf);
multipartEnabled = conf.getBoolean(OSSFileSystemConfigKeys.OSS_MULTIPART_UPLOADS_ENABLED, true);
partSize = conf.getLong(OSS_MULTIPART_UPLOADS_BLOCK_SIZE_PROPERTY, DEFAULT_MULTIPART_BLOCK_SIZE);
maxThreads = conf.getInt(OSS_MULTIPART_UPLOADS_MAX_THREADS_PROPERTY, Integer.MAX_VALUE);
checkArgument(partSize <= MAX_PART_SIZE, "%s must be at most %s", OSS_MULTIPART_UPLOADS_BLOCK_SIZE_PROPERTY, MAX_PART_SIZE);
}
示例7: delete
import com.aliyun.openservices.oss.OSSClient; //导入依赖的package包/类
@Override
public void delete(String file) {
OSSClient client = new OSSClient(uploadUrl, accessKeyId, accessKeySecret);
client.deleteObject(bucketName, file);
}
示例8: setUp
import com.aliyun.openservices.oss.OSSClient; //导入依赖的package包/类
@Before
public void setUp() {
client = mock(OSSClient.class);
Configuration conf = new Configuration();
uploader = new MultiPartUploader(client, bucket, conf);
}
示例9: init
import com.aliyun.openservices.oss.OSSClient; //导入依赖的package包/类
@PostConstruct
public void init() {
client = new OSSClient(url, key,
secret);
}
示例10: getClient
import com.aliyun.openservices.oss.OSSClient; //导入依赖的package包/类
public OSSClient getClient() {
return client;
}
示例11: setClient
import com.aliyun.openservices.oss.OSSClient; //导入依赖的package包/类
public void setClient(OSSClient client) {
this.client = client;
}