oss_resumable_sample.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. #include "aos_log.h"
  2. #include "aos_util.h"
  3. #include "aos_string.h"
  4. #include "aos_status.h"
  5. #include "oss_auth.h"
  6. #include "oss_util.h"
  7. #include "oss_api.h"
  8. #include "oss_config.h"
  9. #include "oss_sample_util.h"
  10. void resumable_upload_with_multi_threads()
  11. {
  12. aos_pool_t *p = NULL;
  13. aos_string_t bucket;
  14. aos_string_t object;
  15. aos_string_t filename;
  16. aos_status_t *s = NULL;
  17. int is_cname = 0;
  18. aos_table_t *headers = NULL;
  19. aos_table_t *resp_headers = NULL;
  20. aos_list_t resp_body;
  21. oss_request_options_t *options = NULL;
  22. oss_resumable_clt_params_t *clt_params;
  23. aos_pool_create(&p, NULL);
  24. options = oss_request_options_create(p);
  25. init_sample_request_options(options, is_cname);
  26. headers = aos_table_make(p, 0);
  27. aos_str_set(&bucket, BUCKET_NAME);
  28. aos_str_set(&object, "my_key_1.zip");
  29. aos_str_set(&filename, "local_big_file.zip");
  30. aos_list_init(&resp_body);
  31. // upload
  32. clt_params = oss_create_resumable_clt_params_content(p, 1024 * 100, 3, AOS_FALSE, NULL);
  33. s = oss_resumable_upload_file(options, &bucket, &object, &filename, headers, NULL,
  34. clt_params, NULL, &resp_headers, &resp_body);
  35. if (aos_status_is_ok(s)) {
  36. printf("upload succeeded\n");
  37. } else {
  38. printf("upload failed\n");
  39. }
  40. aos_pool_destroy(p);
  41. }
  42. void resumable_upload_with_resumable()
  43. {
  44. aos_pool_t *p = NULL;
  45. aos_string_t bucket;
  46. aos_string_t object;
  47. aos_string_t filename;
  48. aos_status_t *s = NULL;
  49. int is_cname = 0;
  50. aos_table_t *headers = NULL;
  51. aos_table_t *resp_headers = NULL;
  52. aos_list_t resp_body;
  53. oss_request_options_t *options = NULL;
  54. oss_resumable_clt_params_t *clt_params;
  55. aos_pool_create(&p, NULL);
  56. options = oss_request_options_create(p);
  57. init_sample_request_options(options, is_cname);
  58. headers = aos_table_make(p, 0);
  59. aos_str_set(&bucket, BUCKET_NAME);
  60. aos_str_set(&object, "my_key_2.zip");
  61. aos_str_set(&filename, "local_big_file.zip");
  62. aos_list_init(&resp_body);
  63. // upload
  64. clt_params = oss_create_resumable_clt_params_content(p, 1024 * 100, 3, AOS_TRUE, NULL);
  65. s = oss_resumable_upload_file(options, &bucket, &object, &filename, headers, NULL,
  66. clt_params, NULL, &resp_headers, &resp_body);
  67. if (aos_status_is_ok(s)) {
  68. printf("upload succeeded\n");
  69. } else {
  70. printf("upload failed\n");
  71. }
  72. aos_pool_destroy(p);
  73. }
  74. void resumable_upload_sample()
  75. {
  76. resumable_upload_with_multi_threads();
  77. resumable_upload_with_resumable();
  78. }
  79. void resumable_download_with_multi_threads()
  80. {
  81. aos_pool_t *p = NULL;
  82. aos_string_t bucket;
  83. aos_string_t object;
  84. aos_string_t filename;
  85. aos_status_t *s = NULL;
  86. int is_cname = 0;
  87. aos_table_t *headers = NULL;
  88. aos_table_t *resp_headers = NULL;
  89. oss_request_options_t *options = NULL;
  90. oss_resumable_clt_params_t *clt_params;
  91. aos_pool_create(&p, NULL);
  92. options = oss_request_options_create(p);
  93. init_sample_request_options(options, is_cname);
  94. headers = aos_table_make(p, 0);
  95. aos_str_set(&bucket, BUCKET_NAME);
  96. aos_str_set(&object, "my_key_1.zip");
  97. aos_str_set(&filename, "local_big_file_1.zip");
  98. // download
  99. clt_params = oss_create_resumable_clt_params_content(p, 1024 * 100, 3, AOS_FALSE, NULL);
  100. s = oss_resumable_download_file(options, &bucket, &object, &filename, headers, NULL,
  101. clt_params, NULL, &resp_headers);
  102. if (aos_status_is_ok(s)) {
  103. printf("download succeeded\n");
  104. } else {
  105. printf("download failed\n");
  106. }
  107. aos_pool_destroy(p);
  108. }
  109. void resumable_download_with_resumable()
  110. {
  111. aos_pool_t *p = NULL;
  112. aos_string_t bucket;
  113. aos_string_t object;
  114. aos_string_t filename;
  115. aos_status_t *s = NULL;
  116. int is_cname = 0;
  117. aos_table_t *headers = NULL;
  118. aos_table_t *resp_headers = NULL;
  119. oss_request_options_t *options = NULL;
  120. oss_resumable_clt_params_t *clt_params;
  121. aos_pool_create(&p, NULL);
  122. options = oss_request_options_create(p);
  123. init_sample_request_options(options, is_cname);
  124. headers = aos_table_make(p, 0);
  125. aos_str_set(&bucket, BUCKET_NAME);
  126. aos_str_set(&object, "my_key_2.zip");
  127. aos_str_set(&filename, "local_big_file_2.zip");
  128. // download
  129. clt_params = oss_create_resumable_clt_params_content(p, 1024 * 100, 3, AOS_TRUE, NULL);
  130. s = oss_resumable_download_file(options, &bucket, &object, &filename, headers, NULL,
  131. clt_params, NULL, &resp_headers);
  132. if (aos_status_is_ok(s)) {
  133. printf("download succeeded\n");
  134. } else {
  135. printf("download failed\n");
  136. }
  137. aos_pool_destroy(p);
  138. }
  139. void resumable_download_sample()
  140. {
  141. resumable_download_with_multi_threads();
  142. resumable_download_with_resumable();
  143. }