Performing an Appendable Upload
If you have any questions during development, post them on the Issues page of GitHub. For details about parameters and usage of each API, see the .
Appendable upload allows you to upload an object in appendable mode and then append data to the object. You can call ObsClient.appendObject to perform an appendable upload. Sample code is as follows:
// Hard-coded or plaintext AK/SK are risky. For security purposes, encrypt your AK/SK and store them in the configuration file or environment variables. In this example, the AK/SK are stored in environment variables for identity authentication. Before running this example, configure environment variables ACCESS_KEY_ID and SECRET_ACCESS_KEY_ID. // Obtain an AK/SK pair on the management console. For details, see https://support.huaweicloud.com/eu/usermanual-ca/ca_01_0003.html. String ak = System.getenv("ACCESS_KEY_ID"); String sk = System.getenv("SECRET_ACCESS_KEY_ID"); String endPoint = "https://your-endpoint"; // Create an instance of ObsClient. ObsClient obsClient = new ObsClient(ak, sk, endPoint); // Upload an object in appendable mode. AppendObjectRequest request = new AppendObjectRequest(); request.setBucketName("bucketname"); request.setObjectKey("objectname"); request.setPosition(0L); request.setInput(new ByteArrayInputStream("Hello OBS".getBytes())); AppendObjectResult result = obsClient.appendObject(request); // Append data to the object. request.setPosition(result.getNextPosition()); request.setInput(new ByteArrayInputStream("Hello OBS Again".getBytes())); result = obsClient.appendObject(request); Log.i("AppendObject", "NextPosition:" + result.getNextPosition()); Log.i("AppendObject", "Etag:" + result.getEtag()); // Use the API for obtaining object properties to get the start position for next appending. ObjectMetadata metadata = obsClient.getObjectMetadata("bucketname", "objectname"); Log.i("AppendObject", "NextPosition from metadata:" + metadata.getNextPosition());
- Objects uploaded using ObsClient.putObject, referred to as normal objects, can overwrite objects uploaded using ObsClient.appendObject, referred to as appendable objects. Data cannot be appended to an appendable object anymore once the object has been overwritten by a normal object.
- When you upload an object for the first time in appendable mode, an exception will be reported (HTTP status code 409) if a common object with the same name is already present.
- The ETag returned for the append upload is the ETag for the appended content, not that for the entire object.
- Data size in each appendable upload cannot exceed 5 GB, and 10,000 times of appendable uploads can be performed on a single object.
- After an appendable upload is successful, you can use AppendObjectResult.getNextPosition or call ObsClient.getObjectMetadata to get the start position for next appending.
- Due to HTTP coding restrictions, non-ASCII characters cannot be sent. If your request headers contain full-width characters, the SDK will URL encode these characters before sending the request. When you use a browser to access the object metadata, the browser automatically decodes the data.
- If you do not need the SDK to decode for you, call AppendObjectRequest.setIsEncodeHeaders(false) to disable auto encoding.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.