05-14-2018 16:32
05-14-2018 16:32
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.
05-15-2018 10:58
Fitbit Developers oversee the SDK and API forums. We're here to answer questions about Fitbit developer tools, assist with projects, and make sure your voice is heard by the development team.
05-15-2018 10:58
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
Best Answer05-15-2018 03:28
05-15-2018 03:28
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}`);
});
}
Best Answer05-15-2018 09:41
Fitbit Developers oversee the SDK and API forums. We're here to answer questions about Fitbit developer tools, assist with projects, and make sure your voice is heard by the development team.
05-15-2018 09:41
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.
Best Answer05-15-2018 10:22
05-15-2018 10:22
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.
Best Answer05-15-2018 10:47
05-15-2018 10:47
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
Best Answer05-15-2018 10:58
Fitbit Developers oversee the SDK and API forums. We're here to answer questions about Fitbit developer tools, assist with projects, and make sure your voice is heard by the development team.
05-15-2018 10:58
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
Best Answer05-15-2018 11:28
05-15-2018 11:28
So, fs.unlinkSync(mySettings.bg); will delete the old image?
Best Answer05-15-2018 11:33
Fitbit Developers oversee the SDK and API forums. We're here to answer questions about Fitbit developer tools, assist with projects, and make sure your voice is heard by the development team.
05-15-2018 11:33
If you replace mySettings.bg with whatever the old filename was.
Best Answer