use of com.aliyun.oss.model.PutObjectRequest in project aliyun-oss-java-sdk by aliyun.
the class GetObjectTest method testGetObjectWithSpecialChars.
@Test
public void testGetObjectWithSpecialChars() {
final String key = "测\\r试-中.~,+\"'*&¥#@%!(文)+字符|?/.zip";
// 128KB
final long inputStreamLength = 128 * 1024;
// TODO: With chinese characters will be failed.
final String metaKey0 = "tag";
final String metaValue0 = "元值0";
try {
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentType(DEFAULT_OBJECT_CONTENT_TYPE);
metadata.addUserMetadata(metaKey0, metaValue0);
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, key, genFixedLengthInputStream(inputStreamLength), metadata);
ossClient.putObject(putObjectRequest);
// Override 1
GetObjectRequest getObjectRequest = new GetObjectRequest(bucketName, key);
OSSObject o = ossClient.getObject(getObjectRequest);
Assert.assertEquals(bucketName, o.getBucketName());
Assert.assertEquals(key, o.getKey());
metadata = o.getObjectMetadata();
Assert.assertEquals(DEFAULT_OBJECT_CONTENT_TYPE, metadata.getContentType());
Assert.assertEquals(metaValue0, metadata.getUserMetadata().get(metaKey0));
Assert.assertEquals(inputStreamLength, metadata.getContentLength());
Assert.assertEquals(o.getRequestId().length(), REQUEST_ID_LEN);
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
use of com.aliyun.oss.model.PutObjectRequest in project zeppelin by apache.
the class OSSNotebookRepo method save.
@Override
public void save(Note note, AuthenticationInfo subject) throws IOException {
String content = note.toJson();
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, rootFolder + "/" + buildNoteFileName(note.getId(), note.getPath()), new ByteArrayInputStream(content.getBytes()));
ossClient.putObject(putObjectRequest);
}
use of com.aliyun.oss.model.PutObjectRequest in project druid by druid-io.
the class OssUtils method uploadFileIfPossible.
/**
* Uploads a file to aliyun OSS if possible. First trying to set ACL to give the bucket owner full control of the file before uploading.
*
* @param client aliyun OSS client
* @param key The key under which to store the new object.
* @param file The path of the file to upload to aliyun OSS.
*/
static void uploadFileIfPossible(OSS client, String bucket, String key, File file) {
final PutObjectRequest putObjectRequest = new PutObjectRequest(bucket, key, file);
log.info("Pushing [%s] to bucket[%s] and key[%s].", file, bucket, key);
client.putObject(putObjectRequest);
}
use of com.aliyun.oss.model.PutObjectRequest in project jeesuite-libs by vakinge.
the class AliyunossProvider method upload.
@Override
public String upload(UploadObject object) {
try {
PutObjectRequest request = null;
if (object.getFile() != null) {
request = new PutObjectRequest(bucketName, object.getFileName(), object.getFile());
} else if (object.getBytes() != null) {
request = new PutObjectRequest(bucketName, object.getFileName(), new ByteArrayInputStream(object.getBytes()));
} else if (object.getInputStream() != null) {
request = new PutObjectRequest(bucketName, object.getFileName(), object.getInputStream());
} else {
throw new IllegalArgumentException("upload object is NULL");
}
PutObjectResult result = ossClient.putObject(request);
if (result.getResponse() == null) {
return isPrivate ? object.getFileName() : urlprefix + object.getFileName();
}
if (result.getResponse().isSuccessful()) {
return result.getResponse().getUri();
} else {
throw new RuntimeException(result.getResponse().getErrorResponseAsString());
}
} catch (OSSException e) {
throw new RuntimeException(e.getErrorMessage());
}
}
use of com.aliyun.oss.model.PutObjectRequest in project aliyun-oss-java-sdk by aliyun.
the class PutObjectTest method testOverridedPutObject.
@Test
public void testOverridedPutObject() throws Exception {
String key = "overrided-put-object";
final int instreamLength = 128 * 1024;
InputStream instream = null;
try {
// Override 1
instream = genFixedLengthInputStream(instreamLength);
ossClient.putObject(bucketName, key, instream);
OSSObject o = ossClient.getObject(bucketName, key);
Assert.assertEquals(key, o.getKey());
Assert.assertEquals(instreamLength, o.getObjectMetadata().getContentLength());
Assert.assertEquals(o.getRequestId().length(), REQUEST_ID_LEN);
// Override 2
final String filePath = genFixedLengthFile(instreamLength);
ossClient.putObject(bucketName, key, new File(filePath));
Assert.assertEquals(instreamLength, new File(filePath).length());
// Override 3
ossClient.putObject(new PutObjectRequest(bucketName, key, new File(filePath)));
o = ossClient.getObject(bucketName, key);
Assert.assertEquals(key, o.getKey());
Assert.assertEquals(instreamLength, o.getObjectMetadata().getContentLength());
Assert.assertEquals(o.getRequestId().length(), REQUEST_ID_LEN);
} catch (Exception ex) {
Assert.fail(ex.getMessage());
}
}
Aggregations