Hi, in our iOS app, I can't seem to access downloaded files.
I downloaded a log file and video file from the web using safari, and our app needs to be able to open it.
On iOS, would we do this using the standard file browsing tool, or something else? EDIT: it seems like we need to use an ios provided solution, example below.
The file types are .log (a text file) and a video .mp4 file.
Looks like plyer only supports picking images? https://github.com/kivy/plyer/blob/master/plyer/platforms/ios/filechooser.py
Main question
What would be a clean way for plyer to support browsing and selecting both?
Could we open the downloads directory if it's something other than .jpg, and then the images browser if image?
However, what if we want to access a downloaded image? How could the user indicate if they want to access downloads vs camera images?
Possible example code for accessing the downloads directory
ChatGPT helped with more info with this example:
from pyobjus import autoclass, objc_str, ObjcCallback
from kivy.app import App
from kivy.uix.button import Button
class FilePickerApp(App):
def build(self):
return Button(text="Pick a File", on_press=self.open_file_picker)
def open_file_picker(self, *args):
UIDocumentPickerViewController = autoclass('UIDocumentPickerViewController')
NSURL = autoclass('NSURL')
# Allow user to pick any file type
file_types = [objc_str("public.item")]
# Create the document picker
picker = UIDocumentPickerViewController.alloc().initWithDocumentTypes_inMode_(
file_types, 0 # 0 = UIDocumentPickerModeImport
)
picker.setAllowsMultipleSelection_(False) # Single file selection
picker.setDelegate_(self)
# Present the picker
UIApplication = autoclass("UIApplication")
app = UIApplication.sharedApplication()
window = app.keyWindow
root_view_controller = window.rootViewController
root_view_controller.presentViewController_animated_completion_(picker, True, None)
# Delegate method to handle file selection
@ObjcCallback
def documentPicker_didPickDocumentsAtURLs_(self, picker, urls):
NSURL = autoclass("NSURL")
for url in urls:
nsurl = NSURL.alloc().initWithString_(url)
file_path = nsurl.path # Convert NSURL to Python-compatible file path
print(f"Selected file path: {file_path}")
# Example: Read the file (if it's a text file)
try:
with open(file_path, "r") as file:
print("File contents:", file.read())
except Exception as e:
print(f"Error reading file: {e}")
# Delegate method to handle cancellation
@ObjcCallback
def documentPickerWasCancelled_(self, picker):
print("File picker cancelled")
FilePickerApp().run()
Hi, in our iOS app, I can't seem to access downloaded files.
I downloaded a log file and video file from the web using safari, and our app needs to be able to open it.
On iOS, would we do this using the standard file browsing tool, or something else?EDIT: it seems like we need to use an ios provided solution, example below.The file types are .log (a text file) and a video .mp4 file.
Looks like plyer only supports picking images? https://github.com/kivy/plyer/blob/master/plyer/platforms/ios/filechooser.py
Main question
What would be a clean way for plyer to support browsing and selecting both?
Could we open the downloads directory if it's something other than .jpg, and then the images browser if image?
However, what if we want to access a downloaded image? How could the user indicate if they want to access downloads vs camera images?
Possible example code for accessing the downloads directory
ChatGPT helped with more info with this example: