05-14-2018 16:32
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

05-14-2018 16:32
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
- Who Voted for this post?
I'm using the new ImagePicker functionality based on the example in the Fitbit blog. I can get it to work but Have a question.When transferring the image from the companion to the device, is there a way to also pass the settings key with the image? I want to be able to save 2 images but when the image is sent from the companion there is currently no way to know if it is for image 1 or image 2.
This is the function that is transferring the image.
function compressAndTransferImage(settingsValue) { const imageData = JSON.parse(settingsValue); Image.from(imageData.imageUri) .then(image => image.export("image/jpeg", { background: "#FFFFFF", quality: 40 }) ) .then(buffer => outbox.enqueue(`${Date.now()}.jpg`, buffer)) .then(fileTransfer => { console.log(`Enqueued ${fileTransfer.name}`); }); }
Answered! Go to the Best Answer.
Accepted Solutions
05-15-2018 10:58
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


05-15-2018 10:58
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
No problem. Don't forget to delete your old image, otherwise you'll run out of space.
https://github.com/Fitbit/sdk-photo-picker/blob/master/app/index.js#L44

05-15-2018 03:28
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

05-15-2018 03:28
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Figured it out, I pass in the image name based on the settings key. Here's the updated function.
settingsStorage.onchange = function(evt) {
if (evt.key === "ccard-front-image" ) {
compressAndTransferImage(evt.newValue, "frontImage.jpg");
} else if (evt.key === "ccard-back-image") {
compressAndTransferImage(evt.newValue, "backImage.jpg");
} };
sendVal(data);
};
function compressAndTransferImage(settingsValue, imageName) { const imageData = JSON.parse(settingsValue); Image.from(imageData.imageUri) .then(image => image.export("image/jpeg", { background: "#FFFFFF", quality: 40 }) ) .then(buffer => outbox.enqueue(imageName, buffer)) .then(fileTransfer => { console.log(`Enqueued ${fileTransfer.name}`); }); }

05-15-2018 09:41
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


05-15-2018 09:41
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
You might need to do some magic on the device so the file has a unique name. The UI won't update just by replacing the image.

05-15-2018 10:22
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

05-15-2018 10:22
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
It works, I pass a unique name for the images to the compressAndTransferImage function. I base the image name on the setting key for the image.

05-15-2018 10:47
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

05-15-2018 10:47
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
I think I spoke too soon. After reading your reply, I tried updating the image and you are correct, it did not work correctly. I added the date to the image name so it will be unique.
thanks

05-15-2018 10:58
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


05-15-2018 10:58
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
No problem. Don't forget to delete your old image, otherwise you'll run out of space.
https://github.com/Fitbit/sdk-photo-picker/blob/master/app/index.js#L44

05-15-2018 11:28
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

05-15-2018 11:28
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
So, fs.unlinkSync(mySettings.bg); will delete the old image?

05-15-2018 11:33
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


05-15-2018 11:33
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
If you replace mySettings.bg with whatever the old filename was.

