RICOH THETA SC2 thumbnail API bug workaround

sc2 thumbnails

Last tested October 7, 2021.

As of firmware 1.64, there seems to be a bug in the SC2 API to get thumbnails from camera.listFiles. A workaround is required to get thumbs from the SC2.

The workaround is in the theta package lib/src/sc2_thumb_get_bytes. You can test the
functionality with the following command.

 dart .\opptheta.dart thumb --sc2=true --save=5

Example Process to Get Thumbnails from SC2

Here is the process to add the SC2 thumbs to your own application.

  1. use camera.listFiles to get a listing of the files on the camera. Pass the number of thumbs you want to get.
  2. parse results → entries
  3. loop through the entries and extract fileUrl. Add it to a list.
  4. go through the fileUrlList and use and HTTP GET request with this URL fileUrl?type=thumb
  5. the thumb will be in bytes. You may want to convert it to base64 if you want to use the same code you have for the Z1 and V thumbnail processing

Alternately, you can use the algorithm above for the Z1 and V models.

Avoid SC2 Lockup Due to Too Many HTTP Requests

Since you are making multiple HTTP requests, the SC2 may lock up if you open and close many HTTP GET requests in sequence.

The solution is to follow this process:

  1. open HTTP client session
  2. send all GET requests through the same client session
  3. close HTTP client session after you have all your thumbnails

Refer to the theta package for a working example.

Code Snippet

import 'dart:convert';
import 'package:theta/src/command.dart';
import 'package:http/http.dart' as http;

Future<List<String>> sc2ThumbGetBytes({int number = 5}) async {
  List<String> thumbList = [];
  List<String> fileUrlList = [];
  Map<String, String> headers = {
    "Content-Type": "application/json;charset=utf-8"
  };
  var client = http.Client();

  try {
    var response = await command(
      'listFiles',
      parameters: {
        'fileType': 'image',
        'entryCount': number,
        'maxThumbSize': 0
      },
    );
    Map<String, dynamic> responseMap = jsonDecode(response);
    var fileList = responseMap['results']['entries'];
    for (var entry in fileList) {
      fileUrlList.add(entry['fileUrl']);
    }
    for (String fileUrl in fileUrlList) {
      var url = Uri.parse('$fileUrl?type=thumb');
      var response = await client.get(url, headers: headers);
      var thumb64 = base64.encode(response.bodyBytes);
      thumbList.add(thumb64);
    }
  } catch (error) {
    print(error);
  } finally {
    client.close();
  }
  return thumbList;
}

If you want to run the snippet to test it, you will need the theta dart package. You can get it from the repository below.

Update Oct 8, 2021

Looking at the official documentation below, I’m now wondering whether it is a bug in the SC2 or just the expected behavior.

theta-web-api-v2.1/commands/camera.list_files.md

image

Though, the V and Z1 definitely show the thumbnails for all the entries as of Oct 8, 2021. Seems like a lot of extra HTTP requests to get the thumbs one by one when it does not seem to be necessary.