Created
March 6, 2020 18:06
-
-
Save prats0599/af65da6fe33abbc4380c103f2b24c889 to your computer and use it in GitHub Desktop.
Unzipping a file on google cloud console
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" Activate your vm instance and run this on a jupyter notebook """ | |
from google.cloud import storage | |
from zipfile import ZipFile | |
from zipfile import is_zipfile | |
import io | |
def zipextract(bucketname, zipfilename_with_path): | |
storage_client = storage.Client() | |
bucket = storage_client.get_bucket(bucketname) | |
destination_blob_pathname = zipfilename_with_path | |
blob = bucket.blob(destination_blob_pathname) | |
zipbytes = io.BytesIO(blob.download_as_string()) | |
if is_zipfile(zipbytes): | |
with ZipFile(zipbytes, 'r') as myzip: | |
for contentfilename in myzip.namelist(): | |
contentfile = myzip.read(contentfilename) | |
blob = bucket.blob(zipfilename_with_path + "/" + contentfilename) | |
blob.upload_from_string(contentfile) | |
zipextract("planet_data", "intel-image-classification.zip") # if the file is gs://planet_data/intel-image-classification.zip |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment