Python urlretrieve a file to Google Cloud Storage -


i trying deploy application on gae.
python script downloads images using urlretrieve function urllib.request package:

urlretrieve(img_url,os.path.join(os.getcwd(),img_dir,str(img_name) + '.jpg')) 

it works fine, long running script locally (to save images locally), unable find alternative doing same gcs.

i appreciate if point me towards how achieve this.

thanks!

the documentation shows how use couple of simple methods read , write cloud storage buckets.

instead of urlretrieve, grab image's contents , write response file in cloud storage.

image_binary = urllib.urlopen(img_url).read() 

and modify cloud storage samples to:

import cloudstorage gcs  def create_file(self, filename, contents, mime_type='image/jpeg'):    write_retry_params = gcs.retryparams(backoff_factor=1.1)   gcs_file = gcs.open(filename,                       'w',                       content_type=mime_type,                       retry_params=write_retry_params)   gcs_file.write(contents)   gcs_file.close()    # maybe other stuff make file publicly   # accessible 

and call write file.


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -