WebView tiene un método llamado¿Cómo permitir la carga de archivos con WebView en Cocoa?
- (void)webView:(WebView *)sender runOpenPanelForFileButtonWithResultListener:(id <WebOpenPanelResultListener>)resultListener
Pero no hay casi 0 doc y detalles sobre el mismo. En el interior, muestro un cuadro de diálogo de archivo abierto y obtengo el nombre del archivo seleccionado.
gusta esta
- (void)webView:(WebView *)sender runOpenPanelForFileButtonWithResultListener:(id <WebOpenPanelResultListener>)resultListener
{
NSOpenPanel* openDlg = [NSOpenPanel openPanel];
[openDlg setCanChooseFiles:YES];
[openDlg setCanChooseDirectories:NO];
// process the files.
if ([openDlg runModal] == NSOKButton)
{
NSString* fileString = [[openDlg URL]absoluteString];
[resultListener chooseFilename:fileString];
}
}
Pero entonces?
¿Qué debo hacer? En el sitio web, muestra que seleccioné un archivo, pero cuando haces clic en cargar el sitio web solo devuelves un error, como si no se carga ningún archivo. ¿Debo escribir el código que maneja la carga del archivo o qué?
Estoy un poco perdido ...
Editar:
De hecho, yo tengo trabajo .... Con sólo modificar el código de aquí: Cocoa webkit: how to get file upload/file system access in webkit un poco, ya que una parte está desfasada
- (void)webView:(WebView *)sender runOpenPanelForFileButtonWithResultListener:(id <WebOpenPanelResultListener>)resultListener
{
// Create the File Open Dialog class.
NSOpenPanel* openDlg = [NSOpenPanel openPanel];
// Enable the selection of files in the dialog.
[openDlg setCanChooseFiles:YES];
// Enable the selection of directories in the dialog.
[openDlg setCanChooseDirectories:NO];
if ([openDlg runModal] == NSOKButton)
{
NSArray* URLs = [openDlg URLs];
NSMutableArray *files = [[NSMutableArray alloc]init];
for (int i = 0; i <[URLs count]; i++) {
NSString *filename = [[URLs objectAtIndex:i]relativePath];
[files addObject:filename];
}
for(int i = 0; i < [files count]; i++)
{
NSString* fileName = [files objectAtIndex:i];
[resultListener chooseFilename:fileName];
}
[files release];
}
}
disfrutar!
¿Cuál es el idioma que está utilizando? –
Objetivo-c, pero lo tengo trabajando ahora – Dimillian
luego borre su pregunta ... –