MCPcopy Create free account
hub / github.com/TimMcCool/scratchattach / upload_asset

Method upload_asset

scratchattach/site/session.py:603–619  ·  view source on GitHub ↗
(self, asset_content, *, asset_id=None, file_ext=None)

Source from the content-addressed store, hash-verified

601 raise (exceptions.FetchError("Failed to download asset"))
602
603 def upload_asset(self, asset_content, *, asset_id=None, file_ext=None):
604 data = asset_content if isinstance(asset_content, bytes) else open(asset_content, "rb").read()
605
606 if isinstance(asset_content, str):
607 file_ext = pathlib.Path(asset_content).suffix
608 file_ext = file_ext.replace(".", "")
609
610 if asset_id is None:
611 asset_id = hashlib.md5(data).hexdigest()
612
613 requests.post(
614 f"https://assets.scratch.mit.edu/{asset_id}.{file_ext}",
615 headers=self._headers,
616 cookies=self._cookies,
617 data=data,
618 timeout=10,
619 )
620
621 # --- Search ---
622

Callers 2

create_soundMethod · 0.80
create_costumeMethod · 0.80

Calls 3

md5Method · 0.80
postMethod · 0.80
readMethod · 0.45

Tested by

no test coverage detected