OSS Image Processing (IMG) is a secure, cost-effective, and highly reliable image processing service that can process large amounts of data. After you upload source images to OSS, you can call RESTful API operations to process the images anytime, anywhere, and on any Internet device.
For more information about the IMG parameters, see Parameters.
Usage
You can use standard HTTP GET requests to access IMG. All processing parameters are encoded in the query string of a URL.
If the ACL of an image object is private, only authorized users can access the image object.
- Anonymous access
OSSTask * task = [_client presignPublicURLWithBucketName:_publicBucketName withObjectKey:@"hasky.jpeg" withParameters:@{@"x-oss-process": @"image/resize,w_50"}];
- Authorized access
When you process images by using OSS SDKs, you can call the
request.setxOssProcess()
operation to configure IMG parameters in the following code. Examples:OSSGetObjectRequest * request = [OSSGetObjectRequest new]; request.bucketName = @"<bucketName>"; request.objectKey = @"example.jpg"; // Process the image. request.xOssProcess = @"image/resize,m_lfit,w_100,h_100"; OSSTask * getTask = [client getObject:request]; [getTask continueWithBlock:^id(OSSTask *task) { if (! task.error) { NSLog(@"download image success!") ; OSSGetObjectResult * getResult = task.result; NSLog(@"download image data: %@", getResult.dowloadedData); } else { NSLog(@"download object failed, error: %@" ,task.error); } return nil; }]; // [getTask waitUntilFinished]; // [request cancel];
- Access by using SDKs
OSSGetObjectRequest * request = [OSSGetObjectRequest new]; request.bucketName = @"bucket-name"; // Specify the bucket name. request.objectKey = @"image-name"; // Specify the name of the image object. request.xOssProcess = @"image/resize,m_lfit,w_100,h_100"; // Scale the image to a fixed width and height of 100. OSSTask * task = [ossClient getObject:request];
Persistent storage of processed images
The following code provides an example on how to save processed images:
OSSImagePersistRequest *request = [OSSImagePersistRequest new];
request.fromBucket = _privateBucketName;
request.fromObject = OSS_IMAGE_KEY;
request.toBucket = _privateBucketName;
request.toObject = @"image_persist_key";
request.action = @"image/resize,w_100";
//request.action = @"resize,w_100";
[[[ossClient imageActionPersist:request] continueWithBlock:^id _Nullable(OSSTask * _Nonnull task) {
return nil;
}] waitUntilFinished];