In almost all cases, you will not need to handle uploading images because the screen manager API will do that for you. There are some situations, such as VR help-lists and turn-by-turn directions, that are not currently covered by the screen manager so you will have manually upload the image yourself in those cases. For more information about uploading images, see the Uploading Images guide.
The FileManager
uploads files and keeps track of all the uploaded files names during a session. To send data with the file manager you need to create either a SdlFile
or SdlArtwork
object. Both SdlFile
s and SdlArtwork
s can be created with using filePath
, or String
.
const audioFile = new SDL.manager.file.filetypes.SdlFile('File Name', SDL.rpc.enums.FileType.AUDIO_MP3, mp3Data, true); const success = await sdlManager.getFileManager().uploadFile(audioFile) .catch(error => { // handle errors here return false; }); if (success) { // File upload successful }
If you want to upload a group of files, you can use the FileManager
batch upload methods. Once all of the uploads have completed you will be notified if any of the uploads failed.
const files = await sdlManager.getFileManager().uploadFiles(sdlFileList) .catch(err => { // handle errors here });
SdlFile
and its subclass SdlArtwork
support uploading persistent files, i.e. files that are not deleted when the car turns off. Persistence should be used for files that will be used every time the user opens the app. If the file is only displayed for short time the file should not be persistent because it will take up unnecessary space on the head unit. You can check the persistence via:
const isPersistent = file.isPersistent();
Be aware that persistence will not work if space on the head unit is limited. The FileManager
will always handle uploading images if they are non-existent.
If a file being uploaded has the same name as an already uploaded file, the new file will be ignored. To override this setting, set the SdlFile
's overwrite
property to true
.
file.setOverwrite(true);
To find the amount of file storage left for your app on the head unit, use the FileManager
’s bytesAvailable
property.
const bytesAvailable = sdlManager.getFileManager().getBytesAvailable();
You can check out if an image has already been uploaded to the head unit via the FileManager
's remoteFileNames
property.
const fileIsOnHeadUnit = sdlManager.getFileManager().getRemoteFileNames().includes(fileName);
Use the file manager’s delete request to delete a file associated with a file name.
const success = await sdlManager.getFileManager().deleteRemoteFileWithName(fileName);
const successes = await sdlManager.getFileManager().deleteRemoteFilesWithNames(remoteFiles);