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
Contributor
BBOldSchool
Posts: 16
Registered: ‎08-15-2011
My Device: 9780
Accepted Solution

Copy file operation

Just wondering how do you do copy file operation?

 

I have a file in my assets folder, it´s an image file, and I just want to copy it to the shared folder, but I can´t achieve this.

 

QFile::copy("assets:///images/image.jpg", "file:///accounts/1000/shared/camera/image.jpg");

 

Is there anything I should first?

Kind of stuck in here

 

Thanks!

Contributor
BBOldSchool
Posts: 16
Registered: ‎08-15-2011
My Device: 9780

Re: Copy file operation

I have been trying with this but still no success.

 

bool CopyFile(constQString& sourceFile,constQString& destinationDir){

 

        QFileInfo fileInfo(sourceFile);
        QString destinationFile = destinationDir + QDir::separator()+ fileInfo.fileName();
        bool result = QFile::copy(sourceFile, destinationFile);
        return result;
}

 

This returns false...

 

Any help?

Developer
jtegen
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10

Re: Copy file operation

Do you have permission to write to the shared folder?
Contributor
BBOldSchool
Posts: 16
Registered: ‎08-15-2011
My Device: 9780

Re: Copy file operation

Yes, in the bar-descriptor.xml access_shared is checked.
May be the code before is wrong, but it's a simple task i'm stucked with.

A simple file copy shouldn't be that hard. Kind of sad...

Developer
Zmey
Posts: 1,512
Registered: ‎12-18-2012
My Device: PlayBook, Z10, DAC

Re: Copy file operation

[ Edited ]

The correct URL prefix is asset:///, not assets:///

But QFile is not a Cascades class and may not understand this prefix at all.

Try:
QString from = QDir::currentPath() + "/app/native/assets/images/image.jpg";
QString to = QDir::homePath() + "../shared/camera/image.jpg";
QFile::copy(from, to);

Also access_shared permission should be set in bar-descriptor.xml

 

upd:

Try logging from & to values and check that folders with these names actually exist on device. If the paths are wrong, adjust them accordingly. Device Filesystem Navigator in Momentics can be used for this.

 


Andrey Fidrya, @zmeyc on twitter
Contributor
BBOldSchool
Posts: 16
Registered: ‎08-15-2011
My Device: 9780

Re: Copy file operation

Okay, I've achieved something... check code below

 

QString from = QDir::currentPath() + "/app/native/assets/images/myImage.jpg";
        QDir(QDir::currentPath() + "/shared/camera/").mkdir("newFolder");
        QString to = QDir::currentPath() + "/shared/camera/newFolder/myImage.jpg";
        QFile::copy(from, to);

 

This is working now, and when I enter the camera to see the photos, i can see the new folder as well. Just guesing if this is working only in developer mode, and if it will be working in release as well.