This example shows how to save a modified file to a stream. Pass any writable binary file-like object (for example an io.BytesIO) to the save method; the wrapper writes the result into it.
importiofromgroupdocs.metadataimportMetadatadefsave_file_to_specified_stream():stream=io.BytesIO()withMetadata("input.png")asmetadata:# Edit or remove metadata heremetadata.sanitize()metadata.save(stream)print(f"Saved {stream.getbuffer().nbytes} bytes to the stream")if__name__=="__main__":save_file_to_specified_stream()
input.png is the sample file used in this example. Click here to download it.