Rameshwar Bhaskar
07/31/2023, 1:18 PM/**
* I am a new handler
* Implicit Functions: preHandler, postHandler, aroundHandler, onMissingAction, onError, onInvalidHTTPMethod
*/
component extends="coldbox.system.RestHandler"{
this.prehandler_only = "";
this.prehandler_except = "";
this.posthandler_only = "";
this.posthandler_except = "";
this.aroundHandler_only = "";
this.aroundHandler_except = "";
this.allowedMethods = {};
property name="s3sdk" inject="AmazonS3@s3sdk";
/**
* Display a listing of the resource
*/
function index( event, rc, prc ){
if (structKeyExists(rc, "image") && isImageFile(rc.image)) {
var fileName = createUUID() & "." & getExtension(rc.image);
s3sdk.putObject(
bucket = s3sdk.getDefaultBucketName(),
key = "coldbox/" & fileName,
file = rc.image,
acl = "public-read"
);
var imageUrl = "https://#s3sdk.getDefaultBucketName()#.<http://s3.amazonaws.com/coldbox/|s3.amazonaws.com/coldbox/>" & fileName;
event.getResponse().addMessage( "Welcome to my ColdBox RESTFul Service" ).setData(imageUrl);
} else {
event.getResponse().addMessage( "Welcome to my ColdBox RESTFul Service" ).setError(true);
}
}
function isImageFile(file) {
var allowedTypes = "image/jpeg,image/png,image/gif";
return listFindNoCase(allowedTypes, file.getContentType());
}
function getExtension(file) {
var parts = listToArray(file.getClientFile(), ".");
return parts[len(parts)];
}
}
but I get an error "An exception ocurred: The function [getClientFile] does not exist in the String."
any solution or any other method to achieve this??? if yes then guide me on how to achieve.aliaspooryorik
var parts = listToArray(file.getClientFile(), "."); then file variable is a string, not an object.Rameshwar Bhaskar
07/31/2023, 1:27 PMrc the image gets as a string that the error comes from.Rameshwar Bhaskar
07/31/2023, 1:40 PMaliaspooryorik
listLast(myfilename, ".") something like thatRameshwar Bhaskar
07/31/2023, 1:47 PMwriteDump(rc);
i get this 👉aliaspooryorik
aliaspooryorik
Rameshwar Bhaskar
07/31/2023, 1:52 PMaliaspooryorik
aliaspooryorik
aliaspooryorik
Rameshwar Bhaskar
07/31/2023, 1:57 PM