What I’m trying to do:
Hello! I’m extremely new to Anvil and not the best with technical terminology but I could really use some help.
I’m trying to build a GUI that allows the user to upload a zip file (from the file loader component) and from Google Colab, I wanted to access the zip the user uploaded to Anvil. I want to be able to actually access it and unzip it from Google Colab.
What I’ve tried and what’s not working:
I’ve tried creating a temporary URL from both Anvil and Google Colab. Both have given me the same error “No such method called TempURL in anvil.media”. I have tried doing anvil.server function calls with no success. I’ve looked all over the forums trying to find a solution but I feel like I’ve exhausted all that I can.
If anyone is able to respond, I’d be fully willing to show my code.
I’ve zero experience with Google Colab, but I have written Anvil Server-side code to unzip zip files that I’ve stored in one of our Anvil Tables. This statement
isn’t clear to me. Does this mean that you are asking Google Colab to do the unzipping?
Oh thank you so much for responding! Yes! Google Colab would do the unzipping of the file. I was just confused on how the user (from Anvil’s side) would upload their file and I would be able to retrieve it from my server side (Google Colab). Hopefully that makes sense . I’ll include my code and pictures if it would be more helpful.
def upload_dataset(self, file, **event_args):
“”“This method is called when a new file is loaded into this FileLoader”“”
c = self.zipUploader ← this is what I named my uploader component
anvil.server.call(‘download_dataset’, c)
Google Colab (Server Side):
import anvil.server
import anvil.media
import zipfile
anvil.server.connect(‘my_token’)
@anvil.server.callable
def download_dataset(zip_media_object): <–this function is where I want to retrieve the zip file from Anvil
with anvil.media.TempFile(zip_media_object) as zip_file_name:
zip_ref = zipfile.ZipFile(zip_file_name, ‘r’)
zip_ref.extractall(“./”+ zip_file_name)
zip_ref.close()
def file_loader_1_change(self, file, **event_args):
"""This method is called when a new file is loaded into this FileLoader"""
if file.name.endswith('.zip'):
anvil.server.call('download_dataset', file)
else:
alert("Please select a ZIP file.")
and this part is in colab, the zip files were apploaded there