File Search APIs

Contents

Search is an essential part of file lookup, and My Cloud Home supports multiple modes of search.

Search by text

This mode of search will search a given text in the file metadata. Since filename is also metadata for the file object, filename search should also use this mode. In this example, the search is for a text called 'hello.' Two files having metadata name 'hello.txt', "helloworld.txt" and "world hello.txt" are returned. The 'location' in the fragments object gives the character index (zero based) of the match in the searched string.


GET /sdk/v2/filesSearch/text?q=hello HTTP/1.1
Host: Endpoint-URL
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJ


{
  "pageToken": "",
  "matches": [
    {
        "file": {
            "id": "CnMytqM8qkRcBjNdB3WCVWk_x2OwqiMEjvjUVrUf",
            "parentID": "sThX0Q3v6ByO9hkm7h5ItBrF7brWeeimnfRD8py0",
            "eTag": "\"CA\"",
            "size": 344,
            "mimeType": "text/plain; charset=utf-8",
            "name": "hello.txt",
            "mTime": "2018-03-23T23:06:59Z",
            "cTime": "2018-03-23T23:07:50.142Z",
            "extension": ".txt",
            "hidden": "none",
            "mimeTypes": [
                "text/plain; charset=utf-8"
            ],
            "trashed": false,
            "family": false
        },
        "fragments": [
            {
                "text": "hello.txt",
                "locations": [
                    {
                        "index": 0,
                        "length": 5
                    }
                ]
            }
        ]
    },
    {
        "file": {
            "id": "bwYzM-TXiw6UbX4bigmr8n3xSRVMEUkD6qFhp76h",
            "parentID": "LgN1O_RHzSPuYvyEEIffnqaB3pQ_7EwijNDhTnuS",
            "eTag": "\"CA\"",
            "size": 344,
            "mimeType": "text/plain; charset=utf-8",
            "name": "helloworld.txt",
            "mTime": "2018-03-23T23:07:17Z",
            "cTime": "2018-03-23T23:08:02.491Z",
            "extension": ".txt",
            "hidden": "none",
            "mimeTypes": [
                "text/plain; charset=utf-8"
            ],
            "trashed": false,
            "family": false
        },
        "fragments": [
            {
                "text": "helloworld.txt",
                "locations": [
                    {
                        "index": 0,
                        "length": 10
                    }
                ]
            }
        ]
    },
    {
        "file": {
            "id": "w1nxFSegq5EhuUp5fyUaKfhCIEOpUYuNOOc1SpLN",
            "parentID": "GN9VWPPEjTm0UJl53fDxkWMZxOBzAY9ohbbUS0E0",
            "eTag": "\"Cg\"",
            "size": 344,
            "mimeType": "text/plain; charset=utf-8",
            "name": "world hello.txt",
            "mTime": "2018-03-23T23:15:00.922Z",
            "cTime": "2018-03-23T23:15:00.922Z",
            "extension": ".txt",
            "hidden": "none",
            "mimeTypes": [
                "text/plain; charset=utf-8"
            ],
            "trashed": false,
            "family": false
        },
        "fragments": [
            {
                "text": "world hello.txt",
                "locations": [
                    {
                        "index": 6,
                        "length": 5
                    }
                ]
            }
        ]
    }
]
}

In another example, searching a text 'samsung' returns two files that have metadata "cameraMake" as samsung.


GET /sdk/v2/filesSearch/text?q=samsung HTTP/1.1
Host: Endpoint-URL
Authorization: Bearer eyJ0eXAiOiJKV1Qi


{
  "pageToken": "",
  "matches": [
    {
      "file": {
        "id": "STAnKEprJWaGMKtv_Yp6SeSiUvcd7qvIGotDdgPG",
        "parentID": "jsViXZXcX70Wbsc627uEAltzqtRQoSfcjxu47Lb_",
        "eTag": "\"Ag\"",
        "size": 2644006,
        "mimeType": "image/jpeg",
        "name": "hc-1433205197536-test.jpg",
        "mTime": "2015-06-02T00:33:27Z",
        "cTime": "2017-02-06T19:21:33.241Z",
        "storageType": "local",
        "extension": ".jpg",
        "hidden": "none",
        "image": {
          "date": "2014:12:10 15:11:54",
          "width": 4128,
          "height": 2322,
          "cameraMake": "SAMSUNG",
          "cameraModel": "GT-I9500",
          "aperture": 2.2,
          "exposureTime": 0.03030303,
          "isoSpeed": 100,
          "focalLength": 4.2,
          "flashFired": false,
          "orientation": 1
        },
        "publiclyShared": false,
        "privatelyShared": false
      },
      "fragments": [
        {
          "text": "SAMSUNG",
          "locations": [
            {
              "index": 0,
              "length": 7
            }
          ]
        }
      ]
    },
    {
      "file": {
        "id": "_EMFULHpu2vfj1r5YkPr3rVq5jB9TzFi-BnL8AIf",
        "parentID": "jsViXZXcX70Wbsc627uEAltzqtRQoSfcjxu47Lb_",
        "eTag": "\"Ag\"",
        "size": 2644006,
        "mimeType": "image/jpeg",
        "name": "hc-1433201481650-test.jpg",
        "mTime": "2015-06-01T23:31:31Z",
        "cTime": "2017-02-06T19:21:33.296Z",
        "storageType": "local",
        "extension": ".jpg",
        "hidden": "none",
        "image": {
          "date": "2014:12:10 15:11:54",
          "width": 4128,
          "height": 2322,
          "cameraMake": "SAMSUNG",
          "cameraModel": "GT-I9500",
          "aperture": 2.2,
          "exposureTime": 0.03030303,
          "isoSpeed": 100,
          "focalLength": 4.2,
          "flashFired": false,
          "orientation": 1
        },
        "publiclyShared": false,
        "privatelyShared": false
      },
      "fragments": [
        {
          "text": "SAMSUNG",
          "locations": [
            {
              "index": 0,
              "length": 7
            }
          ]
        }
      ]
    }
  ]
}

Search a file in a folder

This mode of search will search for a given file in a specified folder. In this example, the search is for a file named 'car' in the root folder.


GET /sdk/v2/filesSearch/parentAndName?parentID=root&name=car.jpg HTTP/1.1
Host: Endpoint-URL
Authorization: Bearer eyJ0eXAiOiJ


{
"id": "su1y2ZXFVz1iFkekTXAs6fP5Kq2lbawR7DYiaf4m",
"parentID": "g4prDyeFphl9rRzc1ioxXRMX_2DWXRBh8yg0ctLS",
"eTag": "\"Cg\"",
"size": 96739,
"mimeType": "image/jpeg",
"name": "car.jpg",
"mTime": "2018-03-23T23:31:53.087Z",
"cTime": "2018-03-23T23:31:53.087Z",
"extension": ".JPG",
"hidden": "none",
"image": {
    "width": 1569,
    "height": 1024,
    "previewAvailable": true,
    "previewSourceWidth": 1569,
    "previewSourceHeight": 1024
},
"mimeTypes": [
    "image/jpeg"
],
"trashed": false,
"family": false
}

APIs

Have question about this section?