Interface to Google Cloud Storage in the security context of the authenticated user. Keep track of every file add/remove in firestore because firebase cloud storage does not allow listing/searching for files. Use the REST API directly because the node.js interface does not include storage.
After initialization the fbstorage module will contain 3 objects:
- .file - file access limited to the current signed-in user
- .app - file access limited to any user of this app but not other apps
- .public - file access without restriction
See
Example
const { fbstorage } = require( 'electron-firebase' )
// get list of folders only accessible to the signed-in user
const fileFolderList = await fbstorage.file.folders()
- fbstorage
- initialize() ⏏
- ~fileStore
- new fileStore(firestoreRoot, storeName, setPrefix)
- .find(filepath, queryMatch) ⇒
object
- .list(folderpath, queryMatch) ⇒
object
- .folders(filepath, content)
- .upload(filepath, content) ⇒
object
- .update(filepath, metadata) ⇒
object
- .download(filepath) ⇒
string
|JSON
|buffer
|object
|array
- .about(filepath) ⇒
Promise
- .delete(filepath) ⇒
null
|string
- ~fileStore
- initialize() ⏏
Firebase Storage interfaces are defined when your app starts (this function must be called after firestore is initialized).
Kind: inner class of initialize
- ~fileStore
- new fileStore(firestoreRoot, storeName, setPrefix)
- .find(filepath, queryMatch) ⇒
object
- .list(folderpath, queryMatch) ⇒
object
- .folders(filepath, content)
- .upload(filepath, content) ⇒
object
- .update(filepath, metadata) ⇒
object
- .download(filepath) ⇒
string
|JSON
|buffer
|object
|array
- .about(filepath) ⇒
Promise
- .delete(filepath) ⇒
null
|string
Create a new fileStore interface.
Param | Type | Description |
---|---|---|
firestoreRoot | string |
a database object defined in firestore.js |
storeName | string |
just a moniker |
setPrefix | string |
the first two segments of the file path, e.g. user/userid |
Search the storage records in the Firestore database for a file matching the specific filepath given. The newest document matching the search criteria will be returned.
Kind: instance method of fileStore
Returns: object
- - metafile descriptor for the requested file
Param | Type | Default | Description |
---|---|---|---|
filepath | string |
Path and filename to store the file in the Cloud | |
queryMatch | string |
"path" |
optional match parameter to query for something other than path |
Search the storage records in the Firestore database for all files where their folder matches the specific path given, and return an array with the metadata for each file.
Kind: instance method of fileStore
Returns: object
- - metafile descriptor for the requested file
Param | Type | Default | Description |
---|---|---|---|
folderpath | string |
Path to query file storage | |
queryMatch | string |
"folder" |
optional match parameter to query for something other than folder |
Return a list of all folders. Folders don't really exist, they are just a slash-separated path construct, the parent of the file path.
Kind: instance method of fileStore
Param | Type |
---|---|
filepath | * |
content | * |
Uploads local content and creates a file in Google Cloud Storage for Firebase, and a record of the file will be kept in the Cloud Firestore database, for easy reference and searching. Accepts contents as string, JSON string, object (serializable), array, or buffer. Returns a Promise containing file metadata, as:
Kind: instance method of fileStore
Returns: object
- - metafile descriptor for the requested file
Param | Type | Description |
---|---|---|
filepath | string |
Path and filename to store the file in the Cloud |
content | string | JSON | buffer | object | array |
File content to be written, objects must be serializable |
Example
{ name: 'users/[user-id]/Test/FileTest',
bucket: 'your-app-here.appspot.com',
generation: '123456789123456',
metageneration: '1',
contentType: 'application/json',
timeCreated: '2019-02-05T03:06:24.435Z',
updated: '2019-02-05T03:06:24.435Z',
storageClass: 'STANDARD',
size: '1005',
md5Hash: 'H3Anb534+vX2Y1HVwJxlyw==',
contentEncoding: 'identity',
contentDisposition: 'inline; filename*=utf-8\'\'FileTest',
crc32c: 'yTf15w==',
etag: 'AAAAAAA=',
downloadTokens: '00000000'
}
Change some metadata aspects of a stored file
Kind: instance method of fileStore
Returns: object
- - metafile descriptor for the requested file
Param | Type | Description |
---|---|---|
filepath | string |
Path and filename to update the file in the Cloud, relative to the current user |
metadata | One or more metadata parameters to change | |
metadata.cacheControl | string |
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control |
metadata.contentDisposition | string |
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/content-Disposition |
metadata.contentEncoding | string |
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Encoding |
metadata.contentLanguage | string |
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Language |
metadata.contentType | string |
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type |
Download a file from Firebase Storage
Kind: instance method of fileStore
Returns: string
| JSON
| buffer
| object
| array
- - file content
Param | Type | Description |
---|---|---|
filepath | string |
Path and filename to retreive the file |
Gets meta information about the file, including a secure download URL that can be used anywhere
Kind: instance method of fileStore
Returns: Promise
- A Promise object representing the meta information about the file
Param | Type | Description |
---|---|---|
filepath | string |
Path and filename to find the file in the Cloud, relative to the current user |
Delete the file from Google Cloud Storage for Firebase and remove the file's record from Cloud Firestore
Kind: instance method of fileStore
Returns: null
| string
- - empty response unless there is an error
Param | Type | Description |
---|---|---|
filepath | string |
Path and filename to delete the file in the Cloud, relative to the current user |