Questions tagged [bytesio]

A stream implementation using an in-memory bytes buffer.

Refer to BytesIO class details in Python's docs.

258 questions
1
vote
1 answer

Document type to bytes in Python

I am creating a PDF in python using the borb library. Everything is great and i've found it really easy to work with. However, I now have an object that is of type 'Document' in memory. I don't want to actually save this file anywhere. I just want…
bruzza42
  • 393
  • 2
  • 13
1
vote
0 answers

Is there a way to split a ByetsIO object into multiple BytesIO objects without reading the stream content?

I have a file coming from a network request, the file ends up being accessible as a BytesIO object, is there any way to split that BytesIO object into multiple BytesIO objects without the overhead of reading the content and manually splitting at a…
1
vote
0 answers

Compress a file while uploading to s3

I'm writing "bytes" to a file on s3 remote, using boto3.client. Is there a way to write data while compressing it simultaneously? eg. using some option like codec="snappy" or something like that? Code: s3 = boto3.client("s3") bytesio =…
vish4071
  • 5,135
  • 4
  • 35
  • 65
1
vote
1 answer

Python PIL.Image.tobytes() gives invalid bytes for image

When I run this pillow code: from PIL import Image image = Image.open(BytesIO(some_bytes)) resized = image.resize((44, 44)) with open('filename.png', 'wb') as file: file.write(resized.tobytes()) No errors occur, but when I go to the file…
1
vote
1 answer

Multiple Pictures in bytes

i am trying to save multiple Pictures in one Bytes object from BytesIO. And later on acces these Pictures again from bytes to Picture. But i certainly don't know much about bytes. Is there a way to put something after one Picture in to the Buffer…
1
vote
1 answer

xhtml2pdf problem with converting html file with polish characters

I am trying to make invoices by creating html file and convert it to pdf and than send as http response. The problem is that those invoices contains polish characters which UTF-8 does not display. I have tried to use ISO-8859-2 to display them, but…
banboniera
  • 89
  • 7
1
vote
2 answers

xhtml2pdf: Output generated PDF as in-memory object (its bytes)

I'm working with Python 3, Django and the xhtml2pdf package. I want to create a PDF from an HTML string, but I don't want to write the PDF on disk, but rather just to get its bytes from memory, as in using BytesIO or StringIO. I've read the…
Xar
  • 7,572
  • 19
  • 56
  • 80
1
vote
3 answers

Django - can't download file (showed as text instead)

I have a pdf in my static files, I need to add it some text and let the user download it, but the download part gives me some problems, here is part of my code: views.py import io from werkzeug.wsgi import FileWrapper from pathlib import Path from…
manuersuper
  • 83
  • 2
  • 9
1
vote
1 answer

Add some bit stream to image png

I've converted the png image to a base 2-bit sequence with the following program from PIL import Image, ImageFile from io import BytesIO out = BytesIO() with Image.open("download.png") as img: img.save(out, format="png") image_in_bytes =…
1
vote
1 answer

Best way to merge multiple PDF's into one, downloaded from Azure Blob Storage using Python?

Am trying to download multiple PDF files from Azure and combine them (using PyPDF2 library) all into one PDF for re-upload into azure. Am currently getting an error of PyPDF2.utils.PdfReadError: Unsupported PNG filter 4 on line pdf =…
zmorano
  • 27
  • 5
1
vote
1 answer

How to create zipFile from arrays of BytesIO - Flask

I create an array of BytesIO - each object is file (text) that save in memory. I try to compress them to zip and download. I get an error '_io.BytesIO' object is not subscriptable'. this is the code: @app.route('/home', methods =['GET','POST']) def…
1
vote
1 answer

Reading first N lines of file on FTP server in Python

I have a CSV file on an FTP server. The file is around 200mb. For now, I am reading the file using the following method, the issue with this implementation is that the file takes too long to download, the retrbinary method takes around 12min to…
1
vote
1 answer

Using a PIL Image with flasks send_file without saving to disk?

I'm saving the PIL image to a io.BytesIO() object. imgByteArr = io.BytesIO() img.save(imgByteArr, format=format) Then trying to return the image to the user. return send_file(img.getvalue(), mimetype="image/" + img_details["ext"].lower()) But I'm…
Lewis Morris
  • 1,916
  • 2
  • 28
  • 39
1
vote
1 answer

Is there a way I can Download images from any search engine with a code like this?

I tried downloading images from bing to a directory but due to some reason the code just executes and gives me nothing.. not even an error.. I used the user-agent HTTP as well.. but it still doesnt seem to be working.. What should i do? from bs4…
Sanskar B.C.
  • 41
  • 1
  • 5
1
vote
1 answer

How to directly send file to client from google storage in python?

I want to send any file to client on request, from google storage , but its downloading locally on server. I don't to download locally rather if any way I can send file to client directly. Currently I am doing this way for download def…