MCPcopy Index your code
hub / github.com/PyGithub/PyGithub / upload_asset_from_memory

Method upload_asset_from_memory

github/GitRelease.py:346–379  ·  view source on GitHub ↗

Uploads an asset. Unlike ``upload_asset()`` this method allows you to pass in a file-like object to upload. Note that this method is more strict and requires you to specify the ``name``, since there's no file name to infer these from. :calls: `POST /repos/{owner}/{r

(
        self,
        file_like: BinaryIO,
        file_size: int,
        name: str,
        content_type: Opt[str] = NotSet,
        label: str = "",
    )

Source from the content-addressed store, hash-verified

344 return github.GitReleaseAsset.GitReleaseAsset(self._requester, resp_headers, data, completed=True)
345
346 def upload_asset_from_memory(
347 self,
348 file_like: BinaryIO,
349 file_size: int,
350 name: str,
351 content_type: Opt[str] = NotSet,
352 label: str = "",
353 ) -> github.GitReleaseAsset.GitReleaseAsset:
354 """
355 Uploads an asset.
356
357 Unlike ``upload_asset()`` this method allows you to pass in a file-like object to upload.
358 Note that this method is more strict and requires you to specify the ``name``, since there's no file name to infer these from.
359 :calls: `POST /repos/{owner}/{repo}/releases/{release_id}/assets <https://docs.github.com/en/rest/reference/repos#upload-a-release-asset>`__
360 :param file_like: binary file-like object, such as those returned by ``open("file_name", "rb")``. At the very minimum, this object must implement ``read()``.
361 :param file_size: int, size in bytes of ``file_like``
362
363 """
364 assert isinstance(name, str), name
365 assert isinstance(file_size, int), file_size
366 assert isinstance(label, str), label
367
368 post_parameters = {"label": label, "name": name}
369 content_type = content_type if content_type is not NotSet else Consts.defaultMediaType
370 headers = {"Content-Type": content_type, "Content-Length": str(file_size)}
371
372 resp_headers, data = self._requester.requestMemoryBlobAndCheck(
373 "POST",
374 self.upload_url.split("{?")[0],
375 parameters=post_parameters,
376 headers=headers,
377 file_like=file_like,
378 )
379 return github.GitReleaseAsset.GitReleaseAsset(self._requester, resp_headers, data, completed=True)
380
381 def get_assets(self) -> PaginatedList[github.GitReleaseAsset.GitReleaseAsset]:
382 """

Callers 2

Calls 1

Tested by

no test coverage detected