Now lets write the byte data into a file : open('img.jpg','wb').write(data) Now lets loop over the chunks of data using res.iter_content(chunk_size=1024) where each chunk will be of size 1024 bytes and concatenate them in our data var only if the chunk is not empty otherwise it can corrupt our file To store the data of the image(byte sequence) lets create a var data initialized with empty byte string data = b'' for chunk in res.iter_content(chunk_size=1024): if(chunk): data += chunk so it would require to download some Kbs of data only res = req.get(img_adrs, stram=True) ![]() We should chunk up the data by streaming. NO, because the 2GB response will be stored in RAM which will possibly cause MemoryError ![]() Now, establish a connection with the server hosting the file using re.get() What if the file is of 2GB ? will it work …. Copy the link address of the desired image Now, lets Code !! import requests as req img_adrs = ' 'įirst lets import request library and store out image link in img_adrs variable res = req.get(img_adrs)
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |