Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
Posts: 55
Registered: ‎02-17-2013
My Device: Z10 LE
My Carrier: Tata Docomo
Accepted Solution

File picker for asset images

Hi,

  Below is the current code 

        FilePicker {
            id:filePicker
            type : FileType.Picture
            title : "Select Wallpaper"
            directories : ["app/native/assets/images/"]
            onFileSelected : {
                console.log("FileSelected signal received : " + selectedFiles);
                
                //make sure to prepend "file://" when using as a source for an ImageView or MediaPlayer
     
            }
            defaultType: FileType.Picture
            sourceRestriction: FilePickerSourceRestriction.LocalOnly
            viewMode: FilePickerViewMode.GridView
        }

 The problem is with the directories. 

I keep getting the Error "Cannot find source"

Anyone has any ideas how I could pick images stored under assets/images/ ?

Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: File picker for asset images

The path will be relative to where the qml file is stored so assuming your qml file is in assets then your path should be just images/


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 55
Registered: ‎02-17-2013
My Device: Z10 LE
My Carrier: Tata Docomo

Re: File picker for asset images

Yeah, I tried that. But get the same error Smiley Sad
In the debug console I get : Directory:json:[{"uri":"images/"}]
Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: File picker for asset images

Yes, I've even tried passing in a complete filepath and it didn't work, it could be that FilePicker does not have access to this area even if it is your own app.

 


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: File picker for asset images

FilePicker runs as a card, which means it's effectively another app. I don't think it can get access to your app's own sandbox data area.

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: File picker for asset images

@peter9477 Thanks of course it is!


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 55
Registered: ‎02-17-2013
My Device: Z10 LE
My Carrier: Tata Docomo

Re: File picker for asset images

Thank you both for helping me out.
Developer
Posts: 36
Registered: ‎09-09-2014
My Device: BB Passport
My Carrier: T-Mobile Czech republic

Re: File picker for asset images

Hello, I have similar problem. There is a subdirectory in my app's assets directory called "listimages" where are some image files for user choice. I implemented selection via FilePicker:

 

ImageView {
                    id: obrazekField
                    onTouch: {
                        obrazekPicker.directories = ["/listimages/"]
                        console.log(obrazekPicker.directories[0])
                        obrazekPicker.open()
                    }
                    preferredWidth: 100.0
                    preferredHeight: 100.0
                    accessibility.description: ""
                    imageSource: "asset:///listimages/ScheduledPays.png"
                    accessibilityMode: A11yMode.Default

                }
                attachedObjects: [
                    FilePicker {
                        idSmiley SurprisedbrazekPicker
                        type : FileType.Picture
                        title : "Select Picture"
                        onFileSelected : {
                            obrazekField.imageSource = "file://" + selectedFiles[0];
                        
                        }
                        defaultType: FileType.Picture
                        viewMode: FilePickerViewMode.Default
                    }
                ]

 

But after activating FilePicker, camera folder is displayed and compiler reports:

 

 
FilePickerPrivate:Smiley SurprisednCardInvokeRequestFinished()  . error= 2
"Unable to open File Picker/Saver Card"
InvokeReply::Error= "2"

 

Is there way to allow select own images with FilePicker ?

 

Thank you for any advice, evenatually with a piece of sample code.

 

Thank you very much.

 

Karel