Performing a Streaming 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 API Reference
Streaming upload uses java.io.InputStream as the data source of an object. You can call ObsClient.putObject to upload the data streams to OBS. Sample code is as follows:
Uploading a Character String (Byte Array)
String endPoint = "https://your-endpoint";
String ak = "*** Provide your Access Key ***";
String sk = "*** Provide your Secret Key ***";
// Create an instance of ObsClient.
ObsClient obsClient = new ObsClient(ak, sk, endPoint);
String content = "Hello OBS";
obsClient.putObject("bucketname", "objectname", new ByteArrayInputStream(content.getBytes()));
Uploading a Network Stream
String endPoint = "https://your-endpoint";
String ak = "*** Provide your Access Key ***";
String sk = "*** Provide your Secret Key ***";
// Create an instance of ObsClient.
ObsClient obsClient = new ObsClient(ak, sk, endPoint);
InputStream inputStream = new URL("http://www.a.com").openStream();
obsClient.putObject("bucketname", "objectname", inputStream);
Uploading a File Stream
String endPoint = "https://your-endpoint";
String ak = "*** Provide your Access Key ***";
String sk = "*** Provide your Secret Key ***";
// Create an instance of ObsClient.
ObsClient obsClient = new ObsClient(ak, sk, endPoint);
FileInputStream fis = new FileInputStream(new File("localfile")); // localfile indicates the path of the local file to be uploaded. You need to specify the file name.
obsClient.putObject("bucketname", "objectname", fis);
- To upload a local file, you are advised to use file-based upload.
- To upload a large file, you are advised to use multipart upload.
- The file to be uploaded cannot exceed 5 GB.
Last Article: Object Upload Overview
Next Article: Performing a File-Based Upload
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.