uploadImage method
Uploads an image to the device.
image is the type of the image (usually 0).
The data will be sent to the device in chunks.
Use McuImage.decode to obtain the hash.
If specified, onProgress will be called after each uploaded chunk.
Its parameter is the number bytes uploaded so far.
Implementation
Future<void> uploadImage(
int image,
List<int> data,
List<int> hash,
Duration chunkTimeout, {
int chunkSize = 128,
void Function(int)? onProgress,
}) async {
int offset = 0;
while (offset != data.length) {
int size = data.length - offset;
if (size > chunkSize) {
size = chunkSize;
}
List<int> chunk = data.sublist(offset, offset + size);
final Future<ImageUploadResponse> future;
if (offset == 0) {
future = startImageUpload(
image,
chunk,
data.length,
hash,
chunkTimeout,
);
} else {
future = continueImageUpload(
offset,
chunk,
chunkTimeout,
);
}
final response = await future;
offset = response.nextOffset;
onProgress?.call(offset);
}
}