Zip file/directory and upload to data API location defined by `DataFile` object. Accepts either a single file or a directory containing other files and directories.
(self, path)
| 164 | raise DataApiError("Attempted to .putNumpy() a file without numpy available, please install numpy.") |
| 165 | |
| 166 | def putAsZip(self, path): |
| 167 | """Zip file/directory and upload to data API location defined by `DataFile` object. |
| 168 | |
| 169 | Accepts either a single file or a directory containing other files and directories. |
| 170 | """ |
| 171 | temp = tempfile.NamedTemporaryFile(delete=False).name |
| 172 | if os.path.isdir(path): |
| 173 | with zipfile.ZipFile(temp, 'w') as ziph: |
| 174 | for root, dirs, files in os.walk(path): |
| 175 | for file in files: |
| 176 | f_path = os.path.join(root, file) |
| 177 | arc_path = os.path.relpath(os.path.join(root, file), path) |
| 178 | ziph.write(f_path, arc_path) |
| 179 | else: |
| 180 | with zipfile.ZipFile(temp, 'w') as ziph: |
| 181 | ziph.write(path) |
| 182 | return self.putFile(temp) |
| 183 | |
| 184 | def delete(self): |
| 185 | # Delete from data api |