This document helps you understand how to save processed images.
Operation Scenarios
Image processing API cannot save processed images to ZOS. It only generates temporary images for return. Therefore, ZOS provides processed image saving functionality to specify the saving locations of the processed images.
Refer to Image Processing Parameters for specific parameters. Persisting processed images allows for more efficient management of bucket image resources.
For requests to save processed images, see the SDK documentation under image processing POST request examples.
Constraints and Restrictions
Permission Requirements
To perform an image transfer operation, the account must have GetObject and PutObject permissions on the source bucket and PutBucket of the destination bucket and PutObject permissions on the object.
Storage Location
The source image bucket and the bucket where the processed images are saved may be the same or different, but they must belong to the same account and the same region.
Example
Sequentially resize and crop an image, and finally save the processed image to the dstBucket. For other operations, see Iimage Processing Parameters and replace imageop with the corresponding operation string.
import com.amazonaws.ClientConfiguration;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.client.builder.AwsClientBuilder;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import com.amazonaws.Protocol;
import com.amazonaws.services.s3.model.GetObjectRequest;
import com.amazonaws.services.s3.model.ProcessObjectRequest;
import com.amazonaws.services.s3.model.S3Object;
import java.io.*;
import java.util.Base64;
public class postPicProcess {
public static String ACCESS_KEY="<your-access-key>";
public static String SECRET_KEY="<your-secret-key>";
public static String END_POINT="<your-endpoint>";
public static String srcBucket="<your-srcBucket>";
public static String dstBucket="<your-dstBucket>";
public static String srcKey="<your-srcKey>";
public static String dstKey="<your-dstKey>";
public static void main(String[ ]args) {
// Declare s3 and bucket name. Replace with your own.
AmazonS3 s3Client;
try{
// When using the HTTPS protocol with self-signed certificates, disable certificate check.
//System.setProperty("com.amazonaws.sdk.disableCertChecking", "true");
// Establish connection with credentials and configuration.
AWSCredentials credentials =new BasicAWSCredentials(ACCESS_KEY, SECRET_KEY);
ClientConfiguration awsClientConfig = new ClientConfiguration();
// Use "S3SignerType" for V2 signing.
awsClientConfig.setSignerOverride("S3SignerType");
// Use "AWSS3V4SignerType" for V4 signing.
//awsClientConfig.setSignerOverride("AWSS3V4SignerType");
// Connection defaults to use the HTTPS protocol. Explicitly specify HTTP if using the HTTP protocol.
awsClientConfig.setProtocol(Protocol.HTTP);
s3Client = AmazonS3ClientBuilder.standard()
.withCredentials(new AWSStaticCredentialsProvider(credentials))
.withClientConfiguration(awsClientConfig)
.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(END_POINT, ""))
.disableChunkedEncoding()
.build();
ProcessObjectRequest request = new ProcessObjectRequest();
request.setBucketName(dstBucket);
request.setKey(dstKey);
request.setProcessSource(srcBucket + "/" + srcKey);
String imageop = "image/resize,p_80/crop,w_500,h_500,x_10,y_10"
request.setZosProcess(imageop);
s3Client.ProcessObject(request);
System.out.print("=====request success=====\n");
}catch (Exception e) {
System.out.print("=====request fail=====\n");
System.out.print(e.getMessage());
}
}
}Code execution method:
javac watermarks.java java watermarks