I need to retrieve the node id of my uploaded files whose Bitcache fingerprints are stored in my file repository (sites/all/files/bitcache/file).

I have been trying to use the Bitcache functions noted in the documentation, however they are not giving me anything useful, so I must be using them incorrectly. Can I get some help on figuring out the NID for any fingerprint stored in the file repository?

For example:

$uri = "bitcache://a0f1d4b7b8471897cfe8ee368a21dbcf9617b7f8";
// uploaded file in bitcache/file/

$url = bitcache_resolve_uri($uri);
// produces: http://example.com/bitcache/a0f1d4b7b8471897cfe8ee368a21dbcf9617b7f8
// I expected a path to the file referenced by the fingerprint data, but that URI = 404

$bid = bitcache_uri_to_id($url);
// produces nothing
// I expected to receive a NID or something similar

$bdata = file_get_contents($url);
// produces nothing, although the file actually contains significant content
// I expected binary output, as this sample is a PDF file

Thank you for any guidance on using Bitcache functions.

Comments

Stupidscript’s picture

Title: Fingerprint Relationship with File Info » Using a Fingerprint to Get a NID
Stupidscript’s picture

Here's how I did it:

.htaccess file in the 'file' directory grabs all requests and redirects to a PHP file containing this script segment:

$file_hash = substr($file_name,0,-4);
$file_sql = "
        SELECT s.uri, fn.nid, ua.title, ur.dst, d.data FROM {rdf_data_file} d
        INNER JOIN {rdf_resources} s ON d.sid = s.rid
        LEFT JOIN {file_nodes} fn ON d.data = fn.uri
        LEFT JOIN {node} ua ON fn.nid = ua.nid
        LEFT JOIN {url_alias} ur ON ur.src = concat('node/', fn.nid)
        WHERE s.uri REGEXP '%s' && d.data REGEXP 'bitcache'
        LIMIT 1
";
$file_getNID = db_fetch_object(db_query($file_sql, $file_hash));

Which gives me the two things I need for my links: the title and the url_alias:

$file_getNID->title
$file_getNID->dst

The query relationships that get me there are:

rdf_data_file.SID = rdf_resources.RID
rdf_data_file.DATA = file_nodes.URI
file_nodes.NID = node.NID
url_alias.SRC = 'node/'.NID

Tweaks welcome.

[Leaving open so others can find it. Close it, if you want to.]