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

Web and WebWorks Development

Reply
New Contributor
Posts: 4
Registered: ‎07-04-2013
My Device: Developing For Blackberry 10

Cannot attach files from sandbox to email.

I'm using WebWorks and having a bunch of logfile that user should be able to send to support dudes. I'm using HTML5 Filesystem API to store logfiles in the sandbox. The problem is: when I'm trying to attach logfile to the email the mail receiver cannot find attachment. Here's the code:

 

var filepath = Logger.fileEntry.toURL();
//file path is something like "filesystem:local:///temporary/logs/Error.log"
blackberry.invoke.card.invokeEmailComposer({
subject: "Email subject",
body: "Email body",
to: ["my@email.com"],
attachment: [filepath]
});

 May you, guys, give me some advice about it? Thanks in advance!

BlackBerry Development Advisor
Posts: 834
Registered: ‎07-15-2008
My Device: Passport
My Carrier: Bell

Re: Cannot attach files from sandbox to email.

What is the actual path that you are using the save the files? Can you try with the absolute file path instead of the URL?

 

How are you saving the file? See the code below for an example:

 

var dataString = JSON.stringify(data);
// un-sandbox file system to access shared folder
blackberry.io.sandbox = false;

window.requestFileSystem  = window.requestFileSystem || window.webkitRequestFileSystem;

window.requestFileSystem(window.PERSISTENT, 1024 * 1024,
	function (fs) {
		fs.root.getFile(blackberry.io.sharedFolder + '/documents/backup.txt', {create: true},
			function (fileEntry) {
				fileEntry.file(function (file) {
					fileEntry.createWriter(function(fileWriter) {
						fileWriter.onwriteend = function(e) {
							fileWriter.onwriteend = null;
							fileWriter.truncate(dataString.length);
							console.log('Write completed.');
							blackberry.ui.toast.show('Data Backed up');
						};

						fileWriter.onerror = function(e) {
							console.log('Write failed: ' + e.toString());
							blackberry.ui.toast.show('Sorry, reading the file failed.');
							};

						var blobData = new Blob([dataString], {type: 'text/json'});
						fileWriter.write(blobData);
					}, _this.errorHandler);
				}, _this.errorHandler);
			}, _this.errorHandler);
	}, _this.errorHandler);

This value should be an absolute path to where the file is being written: blackberry.io.sharedFolder + '/documents/backup.txt'

 Use a folder under blackberry.io.home, and leave out the sandbox part it if you don't want it shared.

Tim Windsor
Open Source Technical Lead
Retired
Posts: 1,561
Registered: ‎04-12-2010
My Device: BlackBerry Z10

Re: Cannot attach files from sandbox to email.

Check out the approach that grahamzibar metnions here:

http://supportforums.blackberry.com/t5/Web-and-WebWorks-Development/Is-it-possible-to-download-image...

 

Specifically, calling the following on the actual file Blob to get a usable path:

 

var pathToFile = window.URL.createObjectURL(imageBlobVariableThing);

Might that resolve the issue?


Erik Oros | @WaterlooErik | eoros@blackberry.com | Developer Issue Tracker

If a reply has answered your question, please click Accept as Solution to help other visitors in the future.