فهرست منبع

增加删除文件

a158 9 ماه پیش
والد
کامیت
4514415526
3فایلهای تغییر یافته به همراه48 افزوده شده و 1 حذف شده
  1. 43 1
      src/aliyunoss.cpp
  2. 2 0
      src/aliyunoss.h
  3. 3 0
      target/aliyunoss.lua

+ 43 - 1
src/aliyunoss.cpp

@@ -128,13 +128,55 @@ std::string module::aliyun_oss::upfile(const std::string& endpoint, const std::s
 
     return return_msg;
 }
+std::string module::aliyun_oss::del(const std::string& endpoint, const std::string& access_key_id, const std::string& access_key_secret, const std::string& bucket_name, const std::string& object_name)
+{
+    aos_pool_t* p = NULL;
+    aos_string_t bucket;
+    aos_string_t object;
+    int is_cname = 0;
+    aos_table_t* headers = NULL;
+    aos_table_t* resp_headers = NULL;
+    oss_request_options_t* options = NULL;
+    aos_status_t* s = NULL;
+
+    aos_pool_create(&p, NULL);
+    options = oss_request_options_create(p);
+
+    options->config = oss_config_create(options->pool);
+    aos_str_set(&options->config->endpoint, endpoint.c_str());
+    aos_str_set(&options->config->access_key_id, access_key_id.c_str());
+    aos_str_set(&options->config->access_key_secret, access_key_secret.c_str());
+    options->config->is_cname = is_cname;
+    options->ctl = aos_http_controller_create(options->pool, 0);
 
+
+
+    headers = aos_table_make(options->pool, 1);
+    apr_table_set(headers, OSS_CONTENT_TYPE, content_type.c_str());
+    aos_str_set(&bucket, bucket_name.c_str());
+    aos_str_set(&object, object_name.c_str());
+
+    s = oss_delete_object(oss_client_options, &bucket, &object, &resp_headers);
+
+    std::string return_msg;
+    if (aos_status_is_ok(s)) {
+
+    }
+    else {
+        return_msg = "delete object failed,code:" + std::to_string(s->code) + ",error_code:" + s->error_code + ",error_msg:" + s->error_msg;
+    }
+
+    aos_pool_destroy(p);
+
+    return return_msg;
+}
 void module::aliyun_oss::regist(sol::state* lua)
 {
     lua->new_usertype<module::aliyun_oss>("fw_aliyunoss",
         "new", sol::constructors<module::aliyun_oss()>(),
         "upfile", &module::aliyun_oss::upfile,
-        "updata", &module::aliyun_oss::updata
+        "updata", &module::aliyun_oss::updata,
+        "del", &module::aliyun_oss::del
     );
 }
 

+ 2 - 0
src/aliyunoss.h

@@ -1,6 +1,7 @@
 #pragma once
 #include "basemodule.h"
 #include "oss_c_sdk/oss_api.h"
+#include <string>
 namespace module
 {
 	/// <summary>
@@ -14,6 +15,7 @@ namespace module
 
 		std::string updata(const std::string& endpoint,const std::string& access_key_id,const std::string& access_key_secret,const std::string& bucket_name,const std::string& object_name,const std::string_view& data);
 		std::string upfile(const std::string& endpoint,const std::string& access_key_id,const std::string& access_key_secret,const std::string& bucket_name,const std::string& object_name,const std::string& filename,const std::string& content_type);
+		std::string del(const std::string& endpoint, const std::string& access_key_id, const std::string& access_key_secret, const std::string& bucket_name, const std::string& object_name);
 		static void regist(sol::state* lua);
 	private:
 		// 通过 imodule 继承

+ 3 - 0
target/aliyunoss.lua

@@ -22,6 +22,9 @@ end
 function aliyun_oss:upfile(endpoint,access_key_id, access_key_secret,bucket_name,object_name,filename,content_type)
     return self.module:upfile(endpoint,access_key_id, access_key_secret,bucket_name,object_name,filename,content_type)
 end
+function aliyun_oss:del(endpoint,access_key_id, access_key_secret,bucket_name,object_name)
+    return self.module:del(endpoint,access_key_id, access_key_secret,bucket_name,object_name)
+end
 function aliyun_oss:self()
     return self.module:self()
 end