Reputation: 13
I have a function that takes a byte array as an argument, uses bytesIO and constructs it into an image, and uploads it to azure blob storage.
It's supposed to look like this:
def foo(b):
img = Image.open(io.BytesIO(b))
container_client = ContainerClient.from_conenction_string(connection_string, container_name)
blob_client = container_client.get_blob_client('fileUpload')
blob_client.upload(img)
But I get the error seek() takes 2 positional arguments but 3 were given
I found this thread but could not get it to work for me.
complete error traceback:
Traceback (most recent call last):
File "c:\WaitingRoom\uploadingfiles\form_recog.py", line 48, in <module>
blob_client.upload_blob(img)
File "C:\Users\355149\AppData\Local\Programs\Python\Python39\lib\site-packages\azure\core\tracing\decorator.py", line 83, in wrapper_use_tracer
return func(*args, **kwargs)
File "C:\Users\355149\AppData\Local\Programs\Python\Python39\lib\site-packages\azure\storage\blob\_blob_client.py", line 706, in upload_blob
options = self._upload_blob_options(
File "C:\Users\355149\AppData\Local\Programs\Python\Python39\lib\site-packages\azure\storage\blob\_blob_client.py", line 361, in _upload_blob_options
length = get_length(data)
File "C:\Users\355149\AppData\Local\Programs\Python\Python39\lib\site-packages\azure\storage\blob\_shared\request_handlers.py", line 87, in get_length
data.seek(0, SEEK_END)
TypeError: seek() takes 2 positional arguments but 3 were given
Upvotes: 0
Views: 2466
Reputation: 1831
I tried with getting bytes from image for testing purpose and upload that bytes to azure blob you can pass your input bytes of image to azure blob using upload_blob
function
import os
import io
from PIL import Image
from azure.storage.blob import BlobServiceClient
from array import array
def readimage(imagepath):
count = os.stat(path).st_size / 2
with open(path, "rb") as f:
return bytearray(f.read())
bytes = readimage("pathtoimage") // getting bytes of image
image = Image.open(io.BytesIO(bytes))
print("hiiiiiiiiiiiiiiiiiiiiii")
#print(bytes)
blob_service_client = BlobServiceClient.from_connection_string("Connection String")
# Initialise container
blob_container_client = blob_service_client.get_container_client("test")
# Get blob
blob_client = blob_container_client.get_blob_client("test.jpg// blob name ")
blob_client.upload_blob(bytes) // uploaded blob with bytes
OUTPUT
The images uploaded as test.jpg
Upvotes: 1