Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The process of uploading files to OSS cloud service using Flutter consists of the following steps:

  1. First, you need to create an instance of the OSS client by providing the endpoint, accessKey and secretKey.
final OSS client = OSS(
  endpoint: 'your_endpoint',
  credentials: Credential(
    accessKey: 'your_accessKey',
    secretKey: 'your_secretKey',
  ),
);
  1. Then, you can create a reference to the object that you want to upload by providing the bucket name and the object key.
final ref = client.ref(bucketName, objectKey);
  1. To upload the file, you can use the putObject method which takes the file path and upload options as parameters.
await ref.putObject(
  filePath,
  options: PutObjectOptions(headers: {key: value}),
);
  1. The upload progress can be tracked using the onProgress callback that returns the current progress percentage and the uploaded bytes.
await ref.putObject(
  filePath,
  options: PutObjectOptions(),
  onProgress: (int progress, int uploadedBytes, int totalBytes) {
    // Handle progress updates
  },
);
  1. Once the upload is completed, you will receive a PutObjectResult containing the ETag and the request ID.
final result = await ref.putObject(filePath);
  1. In case of any errors, you can handle them using the catchError method.
await ref.putObject(filePath).catchError((error) {
  // Handle error
});