|
25 | 25 | # cli4 /accounts/:"${ACCOUNT}"/images/v1 | jq -r '.images[]|.id' | while read image_id ; do cli4 --delete /accounts/:"${ACCOUNT}"/images/v1/::$image_id ; done |
26 | 26 | # |
27 | 27 |
|
| 28 | +# |
| 29 | +# A note about version numbers. |
| 30 | +# this code works with 2.14.2 in a simple way |
| 31 | +# this code works with 2.18.0 is a simple way |
| 32 | +# released between then require at-least one paramater send via files= in order to not trigger a backend API bug |
| 33 | +# |
| 34 | + |
| 35 | +def method_from_library_version(): |
| 36 | + if CloudFlare.__version__ <= '2.14.2': |
| 37 | + print('Using %s version of Cloudflare python library - hence do not need data= or files=; but use files= if passing anything' % (CloudFlare.__version__)) |
| 38 | + return '' |
| 39 | + if CloudFlare.__version__ <= '2.17.0': |
| 40 | + print('Using %s version of Cloudflare python library - hence must use files=' % (CloudFlare.__version__)) |
| 41 | + return 'USE-FILES' |
| 42 | + # with newer library than 2.17.0 (i.e 2.18.0 and above) you should be able to pass just the data version |
| 43 | + print('Using %s version of Cloudflare python library - hence use data= as it is simpler' % (CloudFlare.__version__)) |
| 44 | + return 'USE-DATA' |
| 45 | + |
28 | 46 | def doit(account_name, image_filename): |
29 | 47 |
|
30 | 48 | # https://developers.cloudflare.com/stream/uploading-videos/direct-creator-uploads/ |
@@ -75,25 +93,24 @@ def doit(account_name, image_filename): |
75 | 93 | 'size': image_filesize, |
76 | 94 | } |
77 | 95 |
|
78 | | - # this code works with 2.14.2 in a simpler way |
79 | | - |
80 | 96 | data = None |
81 | 97 | files = None |
82 | | - if CloudFlare.__version__ <= '2.14.2': |
83 | | - print('Using %s version of Cloudflare python library - hence using neither data or files') |
84 | | - else: |
85 | | - # with newer library than 2.17.0 you should be able to pass just the data version |
86 | | - print('Using %s version of Cloudflare python library - hence using %s' % (CloudFlare.__version__, 'data' if CloudFlare.__version__ > '2.17.0' else 'files')) |
87 | | - if CloudFlare.__version__ > '2.17.0': |
88 | | - data = { |
89 | | - 'metadata': json.dumps(metadata_values), |
90 | | - 'expiry': time_plus_one_hour_in_iso, |
91 | | - } |
92 | | - else: |
93 | | - files = { |
94 | | - ('metadata', (None, json.dumps(metadata_values))), |
95 | | - ('expiry', (None, time_plus_one_hour_in_iso)) |
96 | | - } |
| 98 | + |
| 99 | + lib_method = method_from_library_version() |
| 100 | + |
| 101 | + if lib_method == 'USE-FILES': |
| 102 | + files = { |
| 103 | + ('metadata', (None, json.dumps(metadata_values))), |
| 104 | + ('expiry', (None, time_plus_one_hour_in_iso)) |
| 105 | + } |
| 106 | + elif lib_method == 'USE-DATA': |
| 107 | + data = { |
| 108 | + 'metadata': json.dumps(metadata_values), |
| 109 | + 'expiry': time_plus_one_hour_in_iso, |
| 110 | + } |
| 111 | + elif lib_method == '': |
| 112 | + # optionally do nothing or send via files= |
| 113 | + pass |
97 | 114 |
|
98 | 115 | try: |
99 | 116 | r = cf.accounts.images.v2.direct_upload.post(account_id, data=data, files=files) |
|
0 commit comments