putObject method
Implementation
Future<String?> putObject(String objectKey, String filePath,
{String? token,String? contentType = "image/jpeg"}) async {
cosLog("putObject");
var f = File(filePath);
int flength = await f.length();
var req = await getRequest("PUT", objectKey,
headers: {
"content-type": contentType,
"content-length": flength.toString()
},
token: token);
var fs = f.openRead();
await req.addStream(fs);
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;
}
}