Learn what Felgo offers to help your business succeed. Start your free evaluation today! Felgo for Your Business

Forums

OverviewFelgo 2 Support (Qt 5) › Strange behavior with FileUtils.AppDataLocation

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #24228

    Martin

    Hi,

    I take photos in my app and want to move them to the app data location.

    // create photo
            Connections {
                target: nativeUtils
                onCameraPickerFinished: {
                    if(accepted) {
                        console.log("New photo path: " + path)
    
                        // copy picture
                        if(fileUtils.copyFile(path, FileUtils.AppDataLocation + "/" + fileUtils.cropPathAndKeepFilename(path)) === false) {
                            console.error("Cannot copy photo: " + FileUtils.AppDataLocation)
                        }
                      [...]
                    }
                }
            }

    FileUtils.AppDataLocation directs to “17”. So the destination dir is “17/” and it is not possible to copy the file. I thought it should be absolute path to application data dir. Did I miss anything?

    I’m using Mac mini for development and test the app on my iPad via the Felgo Live Server.

    Regards
    Martin

     

     

    #24229

    Alex
    Felgo Team

    Hi Martin,

    FileUtils.AppDataLocation

    is just the enum, please use this to get the actual path:

    fileUtils.storageLocation(FileUtils.AppDataLocation)

    You can also add your remaining path as a second parameter, to get the full absolute path without having to care about the correct concatenation, see https://felgo.com/doc/felgo-fileutils/#storageLocation-method

    Best,
    Alex

    #24232

    Martin

    Hi Alex,

    thank you for the hint.

    But I have still troubles with copying the files as you can see here:

    var dstPath = fileUtils.storageLocation(FileUtils.AppDataLocation)
    // Copy photo to application data dir
    if(fileUtils.copyFile(path, dstPath) === false) {
      console.error("Cannot copy photo to: " + dstPath)
    }

    I get the photo under

    file:///var/mobile/Containers/Data/Application/063D1917-6A5A-41F4-BF57-0560F33E1322/Library/Application%20Support/Felgo%20Live%20Client/temp_CDEB8B89-8AA4-4830-8AD3-480D1385FC67.jpg

    But it cannot be copied to

    /var/mobile/Containers/Data/Application/063D1917-6A5A-41F4-BF57-0560F33E1322/Library/Application Support/Felgo Live Client/

    Does the app need special permissions?

    Regards

    Martin

     

     

    #24236

    Alex
    Felgo Team

    Hi Martin,

    here is a working example:

    import QtQuick 2.5
    import Felgo 3.0
    
    App {
      NavigationStack {
        Page {
          title: "Copy Image"
    
          AppButton {
            anchors.centerIn: parent
            text: "Image"
            onClicked: {
              nativeUtils.displayCameraPicker("Take Photo")
            }
          }
    
          Connections {
            target: nativeUtils
            onCameraPickerFinished: {
              if(accepted) {
                console.log("New photo path: " + path)
    
                var dstPath = fileUtils.storageLocation(FileUtils.AppDataLocation, "Copy_" + fileUtils.cropPathAndKeepFilename(path))
    
                console.log("Qt.resolvedUrl(path) " + Qt.resolvedUrl(path))
                console.log("dstPath " + dstPath)
    
                // Copy photo to application data dir
                if(fileUtils.copyFile(Qt.resolvedUrl(path), dstPath) === false) {
                  console.error("Cannot copy photo to: " + dstPath)
                }
    
                console.debug("file exists " + fileUtils.existsFile(dstPath))
              }
            }
          }
        }
      }
    }
    

    Basically, you need to call Qt.resolvedUrl on the path returned from the camera picker, to use it with the copyFile method. Qt is sometimes a little picky on the format of urls, so calling Qt.resolvedUrl is often handy.

    Let me know if that works for you.

    Best,
    Alex

    #24238

    Martin

    Hi Alex,

    thank you for your efforts. It’s working!

    Regards
    Martin

Viewing 5 posts - 1 through 5 (of 5 total)

RSS feed for this thread

You must be logged in to reply to this topic.

Qt_Technology_Partner_RGB_475 Qt_Service_Partner_RGB_475_padded