aonestar
.public
Tables
(current)
Columns
Constraints
Relationships
Orphan Tables
Anomalies
Routines
sp_tr_bed_type_fix_image_url
Parameters
Name
Type
Mode
Definition
declare image_data bytea; content_type text; s3_file_path text; file_ext text; BEGIN /* Store user image on S3 bucket, clear image data and keep image url instead */ IF (NEW.image is not null) THEN image_data := decode(convert_from(NEW.image, 'UTF8'), 'base64'); NEW.image_url := fn_get_bed_image_url(NEW.image, ''); if NEW.image_url is null then file_ext := case when NEW.image_type like '%image/png%' then '.png' else '.jpg' end; content_type := case when NEW.image_type like '%image/png%' then 'image/png' else 'image/jpeg' end; s3_file_path := format('%s/public/bed_images/%s-%s%s', lower(fn_prop_code()), new.code, md5(NEW.image), file_ext); NEW.image_url := doc.s3_upload_file(s3_file_path, image_data, content_type, is_public => true); PERFORM sp_log_debug('sp_tr_bedtype_fix_image_url', 'Uploed bed image to S3 - '||s3_file_path); NEW.image := null; end if; END IF; RETURN NEW; END;