API возвращает мне этот случайный URL-адрес корзины Google при попытке загрузить в нее файлы большего размера:
https://storage.googleapis.com/...-stor ... -goog-hash
Я пытался добавить к нему PUT, я даже пытался предоставить ему хост, x-goog-content-length-range, x-goog- хэш для каждого фрагмента, когда я их просматриваю, но он продолжает возвращать одну и ту же ошибку, что бы я ни делал:
host:storage.googleapis.com
x-goog-content-length-range:0,16383
x-goog-hash:crc32c=ZVBtjQ==
host;x-goog-content-length-range;x-goog-hash
UNSIGNED-PAYLOAD
Мой код:
def calculate_crc32c(data: bytes):
return base64.b64encode(crc32c(data).to_bytes(4, 'big')).decode('utf-8')
def put_file(api: 'API', file: 'File', data: bytes):
checksum_bs4 = calculate_crc32c(data)
content_length = len(data)
position = 0
def file_chunk_generator(chunk_size=16384):
nonlocal sync_event, data, content_length, position
for i in range(0, len(data), chunk_size):
chunk = data[i:i + chunk_size]
yield chunk
with httpx.Client(http2=False) as request:
response = request.put(
FILES_URL.format(api.document_storage_uri, file.hash),
content=file_chunk_generator(),
headers=(headers := {
**api.session.headers,
'content-length': str(content_length),
'content-type': 'application/octet-stream',
'x-goog-hash': f'crc32c={checksum_bs4}',
})
)
if response.status_code == 302:
position = 0
print("Full google upload detected, continuing")
url = response.headers.get("Location")
print(url)
with httpx.Client(http2=False) as request:
for chunk in file_chunk_generator():
print(f'{position},{position + len(chunk) - 1}')
response = request.put(
url,
content=chunk,
headers={
'host': 'storage.googleapis.com',
'x-goog-content-length-range': f'{position},{(position + len(chunk) -1)}',
'x-goog-hash': f'crc32c={calculate_crc32c(chunk)}',
'Content-Length': str(len(chunk)),
}
)
if response.status_code != 200:
break
else:
print("SUCCESS!!!")
if response.status_code != 200:
raise Exception(f"Put file failed - {response.status_code}\n{response.text}")
else:
print(file.uuid, "uploaded")
Подробнее здесь: https://stackoverflow.com/questions/791 ... google-url
Как мне загрузить на этот URL-адрес Google ⇐ Python
Программы на Python
-
Anonymous
1731909454
Anonymous
API возвращает мне этот случайный URL-адрес корзины Google при попытке загрузить в нее файлы большего размера:
https://storage.googleapis.com/...-storage-bucket-prod/google-oauth2%.../...?X-Goog-Algorithm=GOOG4-RSA-SHA256&X-Goog-Credential=blob-creator-reader%40tctn-eu-services-979d.iam.gserviceaccount.com%2...%2Fauto%2Fstorage%2Fgoog4_request&X-Goog-Date=20241116T214909Z&X-Goog-Expires=59&X-Goog-Signature=...X-Goog-SignedHeaders=host%3Bx-goog-content-length-range%3Bx-goog-hash
Я пытался добавить к нему PUT, я даже пытался предоставить ему хост, x-goog-content-length-range, x-goog- хэш для каждого фрагмента, когда я их просматриваю, но он продолжает возвращать одну и ту же ошибку, что бы я ни делал:
host:storage.googleapis.com
x-goog-content-length-range:0,16383
x-goog-hash:crc32c=ZVBtjQ==
host;x-goog-content-length-range;x-goog-hash
UNSIGNED-PAYLOAD
Мой код:
def calculate_crc32c(data: bytes):
return base64.b64encode(crc32c(data).to_bytes(4, 'big')).decode('utf-8')
def put_file(api: 'API', file: 'File', data: bytes):
checksum_bs4 = calculate_crc32c(data)
content_length = len(data)
position = 0
def file_chunk_generator(chunk_size=16384):
nonlocal sync_event, data, content_length, position
for i in range(0, len(data), chunk_size):
chunk = data[i:i + chunk_size]
yield chunk
with httpx.Client(http2=False) as request:
response = request.put(
FILES_URL.format(api.document_storage_uri, file.hash),
content=file_chunk_generator(),
headers=(headers := {
**api.session.headers,
'content-length': str(content_length),
'content-type': 'application/octet-stream',
'x-goog-hash': f'crc32c={checksum_bs4}',
})
)
if response.status_code == 302:
position = 0
print("Full google upload detected, continuing")
url = response.headers.get("Location")
print(url)
with httpx.Client(http2=False) as request:
for chunk in file_chunk_generator():
print(f'{position},{position + len(chunk) - 1}')
response = request.put(
url,
content=chunk,
headers={
'host': 'storage.googleapis.com',
'x-goog-content-length-range': f'{position},{(position + len(chunk) -1)}',
'x-goog-hash': f'crc32c={calculate_crc32c(chunk)}',
'Content-Length': str(len(chunk)),
}
)
if response.status_code != 200:
break
else:
print("SUCCESS!!!")
if response.status_code != 200:
raise Exception(f"Put file failed - {response.status_code}\n{response.text}")
else:
print(file.uuid, "uploaded")
Подробнее здесь: [url]https://stackoverflow.com/questions/79196125/how-do-i-upload-to-this-google-url[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия