Google Cloud Storage (com.google.cloud.storage) wrapper in CFML, tested on Lucee 5.4.
-
Download all required jars from jar-download.com
-
Copy them in "/libs" (or whatever you want) directory, and than set consequently javaSettings var in you Application.cfc:
this.javaSettings = { LoadPaths = ["/libs" ] }
Download the Json key file from your GCP console, copy it into your project directory.
var storage = new GoogleStorage(
bucket="YOUR_BUCKET_NAME",
pathToJsonFile=ExpandPath("/path/keys.json")
)
dump( storage ) //show all methods
The followings are the public methods you can use:
- getFile
Get details of file. Return struct.
getFile( required String fileId )
- getSignedUrl
Get signed url, valid until now() + minutes passed in arguments. Return url as string.
getSignedUrl( required String minutes, required String fileId )
- deleteFileById
Remove file by name. Return boolean.
deleteFileById( required String fileId )
- listFiles
Get files in bucket. Return array of struct.
You can search for files (including path) starting with prefix argument.
listFiles( String prefix )
- insertFile
Put file in bucket. Return struct of detail of file.
insertFile( required String filePath, required String fileId, required String mimeType, Struct metadata )
Arguments:
- filePath: full path of file to upload. Required
- fileId: full path of file on GPC, without bucket name. Required
- mimeType: mime type of file. Required
- metadata: optional data in a key/value struct to add to the object
- downloadFromUrl
Download file. It is possible to set the filename by passing the fileName argument to the method.
downloadFromUrl( required String fileId, String fileName )
⚠️ The fileId is the full path offile on GPC, without bucket.
-
Use CommandBox. Start server and point your brower to http://127.0.0.1:9011/tests/index.cfm
-
Download the keys json file from your GCP console, copy it into the tests folder.
-
Fit the value of pathToJsonFile arg in the loadStorage() function in /tests/index.cfm
Alessio De Padova [email protected] to start the project.
The Lucee community for support.
Bruce Springsteen for all the music.