What I’m trying to do:
1- save a pdf/image file from data table directly into a google drive folder.
2- get the url link of this saved pdf/image file
What I’ve tried and what’s not working:
1- creat_file() method, it creates a document
2- set_media() method, I get error "Could not find attribute: set_media "
Client
class Form1(Form1Template):
def __init__(self, **properties):
# Set Form properties and Data Bindings.
self.init_components(**properties)
anvil.server.call('say_hello',self.image_1.source)
-------------------
server
@anvil.server.callable
def say_hello(name):
f = app_files.test # test is an empty folder in my google drive
f.create_file(name)
#f.set_media(name)
# paste your code between ```
Well, the answer in the Docs , I guess I was not searching correctly :
Client
class Form1(Form1Template):
def __init__(self, **properties):
# Set Form properties and Data Bindings.
self.init_components(**properties)
anvil.server.call('say_hello',self.image_1.source)
-------------------
server
@anvil.server.callable
def say_hello(name):
f = app_files.test # test is an empty folder in my google drive
f.create_file("test",name) #test is the name of my file
test = f.get("test")
url = test.url
The error you were getting with set_media was because you were using that on a folder, not on a file. In your code, name is not the name of your file but the media object itself. So you can just create a file, then use set_media to be the media object.
@anvil.server.callable
def add_image_to_drive(image):
f = app_files.test #get the folder
new_file = f.create_file("image") #create a new file and specify the name
new_file.set_media(image) #set the file to be the image