5

Python GCS how to rename the file in the internal zip file?

 3 years ago
source link: https://www.codesd.com/item/python-gcs-how-to-rename-the-file-in-the-internal-zip-file.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Python GCS how to rename the file in the internal zip file?

advertisements

Suppose I have a file hosted on GCS on a Python AppEngine project. unfortunately, this file structure is something like:

outer.zip/
  - inner.zip/
    - vid_file
    - png_file

the problem is that the two files inside inner.zip do not have the .mp4 extension on the file, and it's causing all sorts of troubles. How do i rename the files so that it appears like:

outer.zip/
  - inner.zip/
    - vid_file.mp4
    - png_file.png

so that the files inside inner.zip have their extensions?

I keep running into all sorts of limitations since gcs doesn't allow file renaming, unarchiving...etc.

the files aren't terribly large.

P.S. i'm not very familiar with Python, so any code examples would be great appreciated, thanks!


There is absolutely no way to perform any alteration to GCS objects -- full stop. They are exactly the bunch of bytes you decided at their birth (uninterpreted by GCS itself) and thus they will stay.

The best you can do is create a new object which is almost like the original except it fixes little errors and oopses you did when creating the original. Then you can overwrite (i.e completely replace) the original with the new, improved version.

Hopefully it's a one-off terrible mistake you made just once and now want to fix so it's not worth writing a program for that. Just download that GCS object, use normal tools to unzip it and unzip any further zipfiles it may contain, do the fixes on the filesystem with your favorite local filesystem tools, zip things up again, upload/rewrite the final zip to your desired new GCS object -- phew, you're done.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK