1.10.3 Object操作API的签名和示例
优质
小牛编辑
124浏览
2023-12-01
PUT Object
函数签名
/**
* Uploads the specified file to galaxy fds with the specified object name
* under the specified bucket.
*
* @param bucketName The name of the bucket to put the object
* @param objectName The name of the object to put
* @param file The file containing the data to be uploaded to fds
* @return A {@link PutObjectResult} containing the information returned by
* galaxy fds for the newly created object
* @throws GalaxyFDSClientException
*/
public PutObjectResult putObject(String bucketName, String objectName,
File file) throws GalaxyFDSClientException;
/**
* Uploads the data from the specified input stream to galaxy fds with the
* specified object name under the specified bucket.
*
* @param bucketName The name of the bucket to put the object
* @param objectName The name of the object to put
* @param input The stream containing the data to be uploaded to fds
* @param metadata Additional metadata instructing fds how to handle the
* uploaded data
* @return A {@link PutObjectResult} containing the information returned by
* galaxy fds for the newly created object
* @throws GalaxyFDSClientException
*/
public PutObjectResult putObject(String bucketName, String objectName,
InputStream input, FDSObjectMetadata metadata)
throws GalaxyFDSClientException;
示例
File file = new File("/tmp/test");
PutObjectResult result = fdsClient.putObject(BUCKET_NAME, OBJECT_NAME, file);
System.out.println("signature: " + result.getSignature());
FDSObjectMetadata metadata = new FDSObjectMetadata();
metadata.addUserMetadata("x-xiaomi-meta-key", "x-xiaomi-meta-value");
InputStream in = new ByteArrayInputStream("object content".getBytes());
PutObjectResult result = fdsClient.putObject(BUCKET_NAME, OBJECT_NAME, in, metadata);
System.out.println("signature: " + result.getSignature());
POST Object
函数签名
/**
* Uploads the specified file to a galaxy fds bucket, an unique object name
* will be returned after successfully uploading.
*
* @param bucketName The name of the bucket to post the object
* @param file The file containing the data to be uploaded to fds
* @return A {@link PutObjectResult} containing the information returned by
* galaxy fds for the newly created object
* @throws GalaxyFDSClientException
*/
public PutObjectResult postObject(String bucketName, File file)
throws GalaxyFDSClientException;
/**
* Uploads the data from the specified input stream to a galaxy fds bucket, an
* unique object name will be returned after successfully uploading.
*
* @param bucketName The name of the bucket to put the object
* @param input The stream containing the data to be uploaded to fds
* @param metadata Additional metadata instructing fds how to handle the
* uploaded data
* @return A {@link PutObjectResult} containing the information returned by
* galaxy fds for the newly created object
* @throws GalaxyFDSClientException
*/
public PutObjectResult postObject(String bucketName, InputStream input,
FDSObjectMetadata metadata) throws GalaxyFDSClientException;
示例
File file = new File("/tmp/test");
PutObjectResult result = fdsClient.postObject(BUCKET_NAME, file);
System.out.println("objectName: " + result.getObjectName() +
", signature: " + result.getSignature());
FDSObjectMetadata metadata = new FDSObjectMetadata();
metadata.addUserMetadata("x-xiaomi-meta-key", "x-xiaomi-meta-value");
InputStream in = new ByteArrayInputStream("object content".getBytes());
PutObjectResult result = fdsClient.postObject(BUCKET_NAME, in, metadata);
System.out.println("objectName: " + result.getObjectName() +
", signature: " + result.getSignature());
GET Object
函数签名
/**
* Gets the object stored in galaxy fds with the specified name under the
* specified bucket.
*
* @param bucketName The name of the bucket where the object stores
* @param objectName The name of the object to get
* @return The object stored in galaxy fds under the specifed bucket
* @throws GalaxyFDSClientException
*/
public FDSObject getObject(String bucketName, String objectName)
throws GalaxyFDSClientException;
/**
* Gets the object stored in galaxy fds with the specified name under the
* specified bucket.
*
* @param bucketName The name of the bucket where the object stores
* @param objectName The name of the object to get
* @param pos The position to start read
* @return The object stored in galaxy fds under the specifed bucket
* @throws GalaxyFDSClientException
*/
public FDSObject getObject(String bucketName, String objectName, long pos)
throws GalaxyFDSClientException;
示例
FDSObject object = fdsClient.getObject(BUCKET_NAME, OBJECT_NAME);
FDSObjectInputStream in = object.getObjectContent();
HEAD Object
函数签名
/**
* Checks if the object with the specified name under the specified bucket
* exists.
*
* @param bucketName The name of the bucket where the object stores
* @param objectName The name of the object to check
* @return The value true if the specified object exists, otherwise false
* @throws GalaxyFDSClientException
*/
public boolean doesObjectExist(String bucketName, String objectName)
throws GalaxyFDSClientException;
示例
boolean exist = fdsClient.doesObjectExist(BUCKET_NAME, OBJECT_NAME);
PUT Object ACL
函数签名
/**
* Sets the AccessControlList(ACL) of the specified fds object.
*
* @param bucketName The name of the bucket where the object stores
* @param objectName The name of the object to set acl
* @param acl The ACL to set for the specified object
* @throws GalaxyFDSClientException
*/
public void setObjectAcl(String bucketName, String objectName,
AccessControlList acl) throws GalaxyFDSClientException;
示例
AccessControlList acl = new AccessControlList();
Grant grant = new Grant("12346", Permission.READ, GrantType.USER);
acl.addGrant(grant);
fdsClient.setObjectAcl(BUCKET_NAME, OBJECT_NAME, acl);
GET Object ACL
函数签名
/**
* Gets the AccessControlList(ACL) of the specified fds object.
*
* @param bucketName The name of the bucket where the object stores
* @param objectName The name of the object to get acl
* @return The {@link AccessControlList} of the specified object
* @throws GalaxyFDSClientException
*/
public AccessControlList getObjectAcl(String bucketName, String objectName)
throws GalaxyFDSClientException;
示例
AccessControlList acl = fdsClient.getObjectAcl(BUCKET_NAME, OBJECT_NAME);
for (Grant grant : acl.getGrantList()) {
System.out.println("grantee: " + grant.getGranteeId() + ", permission: "
+ grant.getPermission() + ", type: " + grant.getType());
}
GET Object metadata
函数签名
/**
* Gets the meta information of object with the specified name under the
* specified bucket.
*
* @param bucketName The name of the bucket where the object stores
* @param objectName The name of the object to get the meta inforamtion
* @return The meta information of the object with the specified name under
* the specified bucket
* @throws GalaxyFDSClientException
*/
public FDSObjectMetadata getObjectMetadata(String bucketName,
String objectName) throws GalaxyFDSClientException;
示例
FDSObjectMetadata metadata = fdsClient.getObjectMetadata(BUCKET_NAME, OBJECT_NAME);
for (Map.Entry<String, String> entry : metadata.getRawMetadata().entrySet()) {
System.out.println("key: " + entry.getKey() + ", value: " + entry.getValue());
}
DELETE Object
函数签名
/**
* Deletes the object with the specified name under the specified bucket.
*
* @param bucketName The name of the bucket where the object stores
* @param objectName The name of the object to delete
* @throws GalaxyFDSClientException
*/
public void deleteObject(String bucketName, String objectName)
throws GalaxyFDSClientException;
示例
fdsClient.deleteObject(BUCKET_NAME, OBJECT_NAME)
Delete multiple Objects
函数签名
/**
* Deletes objects with specified prefix under specified bucket.
*
* @param bucketName The name of the bucket where the objects store
* @param prefix An optional parameter restricting the response to keys
* beginning with the specified prefix.
* @throws GalaxyFDSClientException
* @return list of failed deletion:
* [
* {
* "object_name": "$OBJECT_NAME",
* "error_code": $ERROR_CODE,
* "error_description": "$ERROR_MESSAGE"
* }
* ,...
* ]
*/
public List<Map<String, Object>> deleteObjects(String bucketName, String prefix)
throws GalaxyFDSClientException;
/**
* Deletes the objects with the specified name under the specified bucket,
* length of objectNameList limit to 1k
* @param bucketName The name of the bucket where the objects store
* @param objectNameList The list of names of the object to delete
* @throws GalaxyFDSClientException
* @return list of failed deletion:
* [
* {
* "object_name": "$OBJECT_NAME",
* "error_code": $ERROR_CODE,
* "error_description": "$ERROR_MESSAGE"
* }
* ,...
* ]
*/
public List<Map<String, Object>> deleteObjects(String bucketName, List<String> objectNameList)
throws GalaxyFDSClientException;
示例
fdsClient.deleteObjects(BUCKET_NAME, "object-prefix");
List<String> objectNames = new ArrayList<String>();
objectNames.add("object-name1");
objectNames.add("object-name2");
fdsClient.deleteObjects(BUCKET_NAME, objectNames);
Restore Object
函数签名
/**
* Restore the object from trash.
*
* @param bucketName The name of the bucket where the object stores
* @param objectName The name of the object to restore
* @throws GalaxyFDSClientException
*/
public void restoreObject(String bucketName, String objectName)
throws GalaxyFDSClientException;
示例
fdsClient.restoreObject(BUCKET_NAME, OBJECT_NAME);
Rename Object
函数签名
/**
* Rename the object with the specified name under the specified bucket.
*
* @param bucketName The name of the bucket where the object stores
* @param srcObjectName The name of the source object
* @param dstObjectName The name of the destination object
* @throws GalaxyFDSClientException
*/
public void renameObject(String bucketName, String srcObjectName, String dstObjectName)
throws GalaxyFDSClientException;
示例
fdsClient.renameObject(BUCKET_NAME, OBJECT_NAME, "dst-object-name");
Prefetch Object
函数签名
/**
* Prefetch the specified object to cdn. The object must have public access
* @param bucketName The name of the bucket where the object stores
* @param objectName The name of the object to prefetch
* @throws GalaxyFDSClientException
*/
public void prefetchObject(String bucketName, String objectName)
throws GalaxyFDSClientException;
示例
fdsClient.prefetchObject(BUCKET_NAME, OBJECT_NAME);
Refresh Object
函数签名
/**
* Refresh the object cached in cdn. The object must have public access
* @param bucketName The name of the bucket where the object stores
* @param objectName The name of the object to refresh
* @throws GalaxyFDSClientException
*/
public void refreshObject(String bucketName, String objectName)
throws GalaxyFDSClientException;
示例
fdsClient.refreshObject(BUCKET_NAME, OBJECT_NAME);
Init multipart upload
函数签名
/**
* Init a multipart upload session
* @param bucketName
* @param objectName
* @return A InitMultipartUploadResult which contains uploadId.
* @throws GalaxyFDSClientException
*/
public InitMultipartUploadResult initMultipartUpload(String bucketName,
String objectName) throws GalaxyFDSClientException;
示例
InitMultipartUploadResult initMultipartUploadResult =
fdsClient.initMultipartUpload(BUCKET_NAME, OBJECT_NAME);
System.out.println(initMultipartUploadResult.getUploadId());
其他
分片上传过程解释
Upload part
函数签名
/**
* Upload a part
* @param bucketName
* @param objectName
* @param uploadId
* @param partNumber The part number of this part.
* @param in
* @return A UploadPartResult which contains the part's ETag.
* @throws GalaxyFDSClientException
*/
public UploadPartResult uploadPart(String bucketName, String objectName,
String uploadId, int partNumber, InputStream in)
throws GalaxyFDSClientException;
示例
InputStream part1 = new ByteArrayInputStream("part 1".getBytes());
UploadPartResult uploadPartResult1 = fdsClient.uploadPart(BUCKET_NAME,
OBJECT_NAME, uploadId, 1, part1);
InputStream part2 = new ByteArrayInputStream("part 2".getBytes());
UploadPartResult uploadPartResult2 = fdsClient.uploadPart(BUCKET_NAME,
OBJECT_NAME, uploadId, 2, part2);
其他
分片上传过程解释
Complete multipart upload
函数签名
/**
* Complete the multipart upload.
* @param bucketName
* @param objectName
* @param uploadId
* @param metadata
* @param uploadPartResultList The UploadPartResult list contains UploadPartResult
* returned by uploadPart.
* @return A PutObjectResult which is the same as the one returned by putObject.
*/
public PutObjectResult completeMultipartUpload(String bucketName,
String objectName, String uploadId, FDSObjectMetadata metadata,
UploadPartResultList uploadPartResultList) throws GalaxyFDSClientException;
示例
PutObjectResult result = fdsClient.completeMultipartUpload(BUCKET_NAME,
OBJECT_NAME, uploadId, metadata, uploadPartResultList);
System.out.println("signature: " + result.getSignature());
其他
分片上传过程解释
Abort multipart upload
函数签名
/**
* Abort the multipart upload session.
* @param bucketName
* @param objectName
* @param uploadId
* @throws GalaxyFDSClientException
*/
public void abortMultipartUpload(String bucketName, String objectName,
String uploadId) throws GalaxyFDSClientException;
示例
fdsClient.abortMultipartUpload(BUCKET_NAME, OBJECT_NAME, uploadId);
其他
分片上传过程解释
Generate presigned URL
函数签名
/**
* Returns a pre-signed URI for accessing Galaxy FDS resource.
*
* @param bucketName The name of the bucket containing the desired object
* @param objectName The name of the desired object
* @param expiration The time at which the returned pre-signed URL will expire
* @return A pre-signed URL which expires at the specified time, and can be
* used to allow anyone to download the specified object from galaxy
* fds, without exposing the owner's Galaxy secret access key.
* @throws GalaxyFDSClientException
*/
public URI generatePresignedUri(String bucketName, String objectName,
Date expiration) throws GalaxyFDSClientException;
/**
* Returns a pre-signed CDN URI for accessing Galaxy FDS resource.
*
* @param bucketName The name of the bucket containing the desired object
* @param objectName The name of the desired object
* @param expiration The time at which the returned pre-signed URL will expire
* @return A pre-signed URL which expires at the specified time, and can be
* used to allow anyone to download the specified object from galaxy
* fds, without exposing the owner's Galaxy secret access key.
* @throws GalaxyFDSClientException
*/
public URI generatePresignedCdnUri(String bucketName, String objectName,
Date expiration) throws GalaxyFDSClientException;
/**
* Returns a pre-signed URI for accessing Galaxy FDS resource.
*
* @param bucketName The name of the bucket containing the desired object
* @param objectName The name of the desired object
* @param expiration The time at which the returned pre-signed URL will expire
* @param httpMethod The HTTP method verb to use for this URL
* @return A pre-signed URL which expires at the specified time, and can be
* used to allow anyone to access the specified object from galaxy
* fds, without exposing the owner's Galaxy secret access key.
* @throws GalaxyFDSClientException
*/
public URI generatePresignedUri(String bucketName, String objectName,
Date expiration, HttpMethod httpMethod) throws GalaxyFDSClientException;
/**
* Returns a pre-signed CDN URI for accessing Galaxy FDS resource.
*
* @param bucketName The name of the bucket containing the desired object
* @param objectName The name of the desired object
* @param expiration The time at which the returned pre-signed URL will expire
* @param httpMethod The HTTP method verb to use for this URL
* @return A pre-signed URL which expires at the specified time, and can be
* used to allow anyone to access the specified object from galaxy
* fds, without exposing the owner's Galaxy secret access key.
* @throws GalaxyFDSClientException
*/
public URI generatePresignedCdnUri(String bucketName, String objectName,
Date expiration, HttpMethod httpMethod) throws GalaxyFDSClientException;
/**
* Returns a pre-signed URI for accessing Galaxy FDS resource.
*
* @param bucketName The name of the bucket containing the desired object
* @param objectName The name of the desired object
* @param subResource The subresource of this request
* @param expiration The time at which the returned pre-signed URL will expire
* @param httpMethod The HTTP method verb to use for this URL
* @return A pre-signed URL which expires at the specified time, and can be
* used to allow anyone to access the specified object from galaxy
* fds, without exposing the owner's Galaxy secret access key.
* @throws GalaxyFDSClientException
*/
public URI generatePresignedUri(String bucketName, String objectName,
SubResource subResource, Date expiration, HttpMethod httpMethod)
throws GalaxyFDSClientException;
/**
* Returns a pre-signed URI for accessing Galaxy FDS resource.
*
* @param bucketName The name of the bucket containing the desired object
* @param objectName The name of the desired object
* @param subResources The subresource list of this request
* @param expiration The time at which the returned pre-signed URL will expire
* @param httpMethod The HTTP method verb to use for this URL
* @return A pre-signed URL which expires at the specified time, and can be
* used to allow anyone to access the specified object from galaxy
* fds, without exposing the owner's Galaxy secret access key.
* @throws GalaxyFDSClientException
*/
public URI generatePresignedUri(String bucketName, String objectName,
List<String> subResources, Date expiration, HttpMethod httpMethod)
throws GalaxyFDSClientException;
/**
* Returns a pre-signed CDN URI for accessing Galaxy FDS resource.
*
* @param bucketName The name of the bucket containing the desired object
* @param objectName The name of the desired object
* @param subResource The subresource of this request
* @param expiration The time at which the returned pre-signed URL will expire
* @param httpMethod The HTTP method verb to use for this URL
* @return A pre-signed URL which expires at the specified time, and can be
* used to allow anyone to access the specified object from galaxy
* fds, without exposing the owner's Galaxy secret access key.
* @throws GalaxyFDSClientException
*/
public URI generatePresignedCdnUri(String bucketName, String objectName,
SubResource subResource, Date expiration, HttpMethod httpMethod)
throws GalaxyFDSClientException;
/**
* Returns a pre-signed CDN URI for accessing Galaxy FDS resource.
*
* @param bucketName The name of the bucket containing the desired object
* @param objectName The name of the desired object
* @param subResources The subresource list of this request
* @param expiration The time at which the returned pre-signed URL will expire
* @param httpMethod The HTTP method verb to use for this URL
* @return A pre-signed URL which expires at the specified time, and can be
* used to allow anyone to access the specified object from galaxy
* fds, without exposing the owner's Galaxy secret access key.
* @throws GalaxyFDSClientException
*/
public URI generatePresignedCdnUri(String bucketName, String objectName,
List<String> subResources, Date expiration, HttpMethod httpMethod)
throws GalaxyFDSClientException;
示例
URI uri = fdsClient.generatePresignedUri(BUCKET_NAME, OBJECT_NAME,
new Date(2016, 2, 3));
URI uri = fdsClient.generatePresignedUri(BUCKET_NAME, OBJECT_NAME,
new Date(2016, 2, 3), HttpMethod.PUT);
URI uri = fdsClient.generatePresignedUri(BUCKET_NAME, OBJECT_NAME, SubResource.UPLOADS,
new Date(2016, 2, 3), HttpMethod.PUT);
List<String> subResources = new ArrayList<String>();
subResources.add(SubResource.UPLOAD_ID.name());
subResources.add(SubResource.PART_NUMBER.name());
URI uri = fdsClient.generatePresignedUri(BUCKET_NAME, OBJECT_NAME, subResources,
new Date(2016, 2, 3), HttpMethod.PUT);
URI uri = fdsClient.generatePresignedCdnUri(BUCKET_NAME, OBJECT_NAME,
new Date(2016, 2, 3));
URI uri = fdsClient.generatePresignedCdnUri(BUCKET_NAME, OBJECT_NAME,
new Date(2016, 2, 3), HttpMethod.PUT);
URI uri = fdsClient.generatePresignedCdnUri(BUCKET_NAME, OBJECT_NAME, SubResource.UPLOADS,
new Date(2016, 2, 3), HttpMethod.PUT);
List<String> subResources = new ArrayList<String>();
subResources.add(SubResource.UPLOAD_ID.name());
subResources.add(SubResource.PART_NUMBER.name());
URI uri = fdsClient.generatePresignedCdnUri(BUCKET_NAME, OBJECT_NAME, subResources,
new Date(2016, 2, 3), HttpMethod.PUT);