Skip to content

Resume upload api default to v2 #460

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
max-parallel: 1
matrix:
python_version: ['2.7', '3.4', '3.5', '3.6', '3.7', '3.8', '3.9']
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- name: Checkout repo
uses: actions/checkout@v2
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

*.py[cod]

tests/cases/env
my-test-env.sh

##
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Changelog
## 7.17.0
* 对象存储,分片上传默认使用 V2 接口

## 7.16.0
* 对象存储,优化并发场景的区域查询
* CDN,查询域名带宽,支持 `data_type` 参数
Expand Down
4 changes: 2 additions & 2 deletions examples/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# flake8: noqa
# import hashlib

from qiniu import Auth, put_file, urlsafe_base64_encode
from qiniu import Auth, put_file_v2, urlsafe_base64_encode
import qiniu.config
from qiniu.compat import is_py2, is_py3

Expand Down Expand Up @@ -37,7 +37,7 @@
# 'x-qn-meta-md5': hasher.hexdigest()
# }

ret, info = put_file(
ret, info = put_file_v2(
token,
key,
localfile
Expand Down
4 changes: 2 additions & 2 deletions examples/upload_callback.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
# flake8: noqa

from qiniu import Auth, put_file
from qiniu import Auth, put_file_v2

access_key = '...'
secret_key = '...'
Expand All @@ -22,6 +22,6 @@

localfile = './sync/bbb.jpg'

ret, info = put_file(token, key, localfile)
ret, info = put_file_v2(token, key, localfile)
print(info)
assert ret['key'] == key
4 changes: 2 additions & 2 deletions examples/upload_pfops.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
# flake8: noqa
from qiniu import Auth, put_file, urlsafe_base64_encode
from qiniu import Auth, urlsafe_base64_encode, put_file_v2

access_key = '...'
secret_key = '...'
Expand Down Expand Up @@ -33,6 +33,6 @@

localfile = './python_video.flv'

ret, info = put_file(token, key, localfile)
ret, info = put_file_v2(token, key, localfile)
print(info)
assert ret['key'] == key
4 changes: 2 additions & 2 deletions examples/upload_with_qvmzone.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
# flake8: noqa

from qiniu import Auth, put_file, urlsafe_base64_encode
from qiniu import Auth, put_file_v2
import qiniu.config
from qiniu import Zone, set_default

Expand Down Expand Up @@ -34,6 +34,6 @@
scheme='http')
set_default(default_zone=zone)

ret, info = put_file(token, key, localfile)
ret, info = put_file_v2(token, key, localfile)
print(info)
assert ret['key'] == key
4 changes: 2 additions & 2 deletions examples/upload_with_zone.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
# flake8: noqa

from qiniu import Auth, put_file
from qiniu import Auth, put_file_v2
from qiniu import Zone, set_default

# 需要填写你的 Access Key 和 Secret Key
Expand Down Expand Up @@ -38,5 +38,5 @@
scheme='https')
set_default(default_zone=zone)

ret, info = put_file(token, key, localfile)
ret, info = put_file_v2(token, key, localfile)
print(info)
4 changes: 2 additions & 2 deletions qiniu/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

# flake8: noqa

__version__ = '7.16.0'
__version__ = '7.17.0'

from .auth import Auth, QiniuMacAuth

Expand All @@ -19,7 +19,7 @@

from .services.storage.bucket import BucketManager, build_batch_copy, build_batch_rename, build_batch_move, \
build_batch_stat, build_batch_delete, build_batch_restoreAr, build_batch_restore_ar
from .services.storage.uploader import put_data, put_file, put_stream
from .services.storage.uploader import put_data, put_file, put_file_v2, put_stream, put_stream_v2
from .services.storage.upload_progress_recorder import UploadProgressRecorder
from .services.cdn.manager import CdnManager, DataType, create_timestamp_anti_leech_url, DomainManager
from .services.processing.pfop import PersistentFop
Expand Down
13 changes: 7 additions & 6 deletions qiniu/services/storage/legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
from qiniu import config, http
from qiniu.auth import Auth
from qiniu.compat import json
from qiniu.utils import _file_iter, crc32, rfc_from_timestamp, urlsafe_base64_encode
from qiniu.utils import _file_iter, crc32, rfc_from_timestamp, urlsafe_base64_encode, deprecated

from qiniu.services.storage.upload_progress_recorder import UploadProgressRecorder


@deprecated("use uploader instead")
class _Resume(object):
"""deprecated 断点续上传类
Expand Down Expand Up @@ -85,7 +86,7 @@ def recovery_from_record(self):
return 0, None, None
try:
if not record['modify_time'] or record['size'] != self.size or \
record['modify_time'] != self.modify_time:
record['modify_time'] != self.modify_time:
if self.version == 'v1':
return 0
elif self.version == 'v2':
Expand All @@ -106,8 +107,8 @@ def recovery_from_record(self):
return record['offset']
elif self.version == 'v2':
if not record.__contains__('etags') or len(record['etags']) == 0 or \
not record.__contains__('expired_at') or float(record['expired_at']) < time.time() or \
not record.__contains__('upload_id'):
not record.__contains__('expired_at') or float(record['expired_at']) < time.time() or \
not record.__contains__('upload_id'):
return 0, None, None
self.blockStatus = record['etags']
return record['offset'], record['upload_id'], record['expired_at']
Expand Down Expand Up @@ -178,7 +179,7 @@ def _upload_v2(self):
offset, self.uploadId, self.expiredAt = self.recovery_from_record()
is_resumed = False
if offset > 0 and self.blockStatus != [] and self.uploadId is not None \
and self.expiredAt is not None:
and self.expiredAt is not None:
self.recovery_index = self.blockStatus[-1]['partNumber'] + 1
is_resumed = True
else:
Expand All @@ -201,7 +202,7 @@ def _upload_v2(self):
if config.get_default('default_zone').up_host_backup:
host = config.get_default('default_zone').up_host_backup
else:
host = config.get_default('default_zone')\
host = config.get_default('default_zone') \
.get_up_host_backup_by_token(self.up_token, self.hostscache_dir)

if info.need_retry():
Expand Down
Loading
Loading