document the api filedata call

This commit is contained in:
zotlabs 2016-12-07 15:22:26 -08:00
parent 346a48d4c2
commit 07706b41f4
3 changed files with 70 additions and 4 deletions

66
doc/api/api_filedata.md Normal file
View File

@ -0,0 +1,66 @@
API filedata
=============
Provides the ability to download a file from cloud storage in chunks
GET /api/z/1.0/filedata
Required:
- file_id
attach.hash of desired file ('begins with' match)
Optional:
- start
starting byte of returned data in file (counting from 0)
- length
length (prior to base64 encoding) of chunk to download
Returns:
attach (DB) structure with base64 encoded 'content' comprised of the desired chunk
Example:
https://xyz.macgirvin.com/api/z/1.0/filedata?f=&file_id=9f5217770fd&start=0&length=48
Returns:
{
"attach": {
"id": "107",
"aid": "1",
"uid": "2",
"hash": "9f5217770fd55d563bd77f84d534d8e119a187514bbd391714626cd9c0e60207",
"creator": "pgcJx1IQjuPkx8aI9qheJlBMZzJz-oTPjHy3h5pWlOVOriBO_cSiUhhqwhuZ74TYJ8_ECO3pPiRMWC0q8YPCQg",
"filename": "pcxtopbm.c",
"filetype": "application/octet-stream",
"filesize": "3934",
"revision": "0",
"folder": "",
"flags": "0",
"is_dir": "0",
"is_photo": "0",
"os_storage": "1",
"os_path": "",
"display_path": "",
"content": "LyogcGN4dG9wYm0uYyAtIGNvbnZlcnQgUEMgcGFpbnRicnVzaCAoLnBjeCkgZmls",
"created": "2016-07-24 23:13:01",
"edited": "2016-07-24 23:13:01",
"allow_cid": "",
"allow_gid": "",
"deny_cid": "",
"deny_gid": "",
"start": 0,
"length": 48
}
}

View File

@ -27,9 +27,9 @@ api/z/1.0/filemeta
Export file metadata for any uploaded file Export file metadata for any uploaded file
api/z/1.0/filedata [api/z/1.0/filedata](help/api/api_filedata)
Export file contents for any uploaded file Fetch file contents or partial contents for any uploaded file
api/z/1.0/file/export api/z/1.0/file/export

View File

@ -157,9 +157,9 @@
$start = (($_REQUEST['start']) ? intval($_REQUEST['start']) : 0); $start = (($_REQUEST['start']) ? intval($_REQUEST['start']) : 0);
$length = (($_REQUEST['length']) ? intval($_REQUEST['length']) : 0); $length = (($_REQUEST['length']) ? intval($_REQUEST['length']) : 0);
$r = q("select * from attach where uid = %d and hash = '%s' limit 1", $r = q("select * from attach where uid = %d and hash like '%s' limit 1",
intval(api_user()), intval(api_user()),
dbesc($_REQUEST['file_id']) dbesc($_REQUEST['file_id'] . '%')
); );
if($r) { if($r) {
$ptr = $r[0]; $ptr = $r[0];