putObjectWithFileData method

Future<String?> putObjectWithFileData(
  1. String objectKey,
  2. List<int> fileData, {
  3. String? token,
  4. String? contentType = "image/jpeg",
})

Implementation

Future<String?> putObjectWithFileData(String objectKey, List<int> fileData,
    {String? token,String? contentType = "image/jpeg"}) async {
  cosLog("putObject");
  int fileLength = fileData.length;
  var req = await getRequest("PUT", objectKey,
      headers: {
        "content-type": contentType,
        "content-length": fileLength.toString()
      },
      token: token);
  req.add(fileData);
  var response = await req.close();
  cosLog("request-id:" + (response.headers["x-cos-request-id"]?.first ?? ""));
  if (response.statusCode != 200) {
    String content = await response.transform(utf8.decoder).join("");
    cosLog("putObject error content: $content");
    return null;
  } else {
    return objectKey;
  }
}