import 'dart:io';

import 'package:aliyun_oss_flutter/aliyun_oss_flutter.dart';
import 'package:flutter/material.dart';

class AliYunOss {
  static String ossEndpoint = "oss-accelerate.aliyuncs.com";//'oss-accelerate.aliyuncs.com';
  static String bucketName = 'yunkonjian';
  static String accessKey = 'LTAI5tCzyoR4dRk7WJqRdoe1';
  static String accessSecret = 'OfUTaO1rUE9AyQ9x8xG3YMVvopc9JR';
  // static String bucketUrl = "akaishenz.oss-accelerate.aliyuncs.com";akaishenz.oss-cn-shenzhen.aliyuncs.com
  static initAliyunOss() async {
    // 初始化OSSClient
    OSSClient.init(
      endpoint: ossEndpoint,
      bucket: bucketName,
      credentials: () {
        // Future Credentials
        return Future.value(Credentials(
          accessKeyId: accessKey,
          accessKeySecret: accessSecret,
        ));
        // Or Credentials Config
      },
    );
  }

  // Credentials credentialss() {
  //   return Credentials(
  //     accessKeyId: accessKey,
  //     accessKeySecret: accessSecret,
  //   );
  // }

  Future<String> upload(String path) async {
    final object = await OSSClient().putObject(
      object: OSSImageObject.fromFile(
        file: File(path),
      ),
      bucket: bucketName, // String?
      endpoint: ossEndpoint, // String?
    );
    return object.url;
  }
}
