I’m trying to stream a file from one webserver (Jfrog) to another (nexus content server).
I have working code that does this like this:
def get_file():
url = "https://webserver.com/big_file.zip"
with requests.get(url,, stream=True) as file_stream:
self.stream_file_to_webserver(file_stream)
def stream_file_to_webserver(file_stream):
upload_url = "https://nexus.com/big_file.zip"
with requests.put(upload_url, data=file_stream.iter_content(chunk_size=8192), headers={'Content-Type': 'application/octet-stream'}) as response:
if response.status_code != 201:
print("Success")
This works fine, but I need to upload to the Nexus content server in a different (because of another issue with other metadata fields missing when you upload this way).
There I want to upload this way:
import requests
from requests.auth import HTTPBasicAuth
class FileWrapper:
def __init__(self, file_iterator):
self.file_iterator = file_iterator
def read(self, size=-1):
return next(self.file_iterator, b'')
def get_file():
url = "https://webserver.com/big_file.zip"
with requests.get(url,, stream=True) as file_stream:
self.stream_file_to_webserver(file_stream)
def stream_file_to_webserver(source_response):
upload_url = f"https://nexus.com/repository"
file_wrapper = FileWrapper(source_response.iter_content(chunk_size=8192))
payload = {
'raw.directory': ('/'),
'raw.asset1.filename': ('big_file.zip'),
'raw.asset1': ('big_file.zip', file_wrapper)
}
with requests.post(upload_url, files=payload) as response:
if response.status_code == 201:
print("File uploaded to Nexus successfully.")
else:
print(f"Failed {response.text}")
But this seems to fail because somehow the payload is not set correctly.
[{"id":"directory","message":"Missing required component field 'Directory'"},{"id":"filename","message":"Missing required asset field 'Filename' on '1'"},{"id":"filename","message":"Missing required asset field 'Filename' on '2'"},{"id":"filename","message":"Missing required asset field 'Filename' on '3'"},{"id":"*","message":"The assets 1 and 2 have identical coordinates"},{"id":"*","message":"The assets 2 and 3 have identical coordinates"}]
Does anyone know what I am doing wrong and how I can fix this?