Skip to main content

Template handler deleting an image

This document covers sample implementations for template POST handler deleting uploaded images using the plug-in image browser. All examples deletes uploaded images from the plug-in sample application table UC_FROALA_SAMPLE_BLOBS.

handler features

Requirements

Handler deleting an uploaded image must meet the following requirements:

  1. must use POST method
  2. must be compilable at the run time
  3. must return 200 HTTP status on success

Handler definition

AttributeValue
RESTful Service ModuleA custom RESTservice
Module Base Path/customrest/
URI Templatedelete-simple
Full URLhttps://example-domain.com/ords/workspacename/customrest/delete-simple
Handler MethodPOST
Source TypePL/SQL
Mime Types AllowedNot defined

Handler parameters

The upload handler doesn't require registering any resource parameters as long as REST specific bind variable :status_code is used to set request HTTP status. The request query parameters are accessibile in the PL/SQL code as bind variables with same name.

Handler Source

The handler deleting uploaded image must be defined as PL/SQL.

declare
v_image_id varchar2(4000) := :imageId;
begin
begin
if v_image_id is null then
raise_application_error(-20001, 'image id is missing');
end if;

delete from UC_FROALA_SAMPLE_BLOBS where id = v_image_id;

if SQL%ROWCOUNT = 0 then
raise no_data_found;
end if;

:status_code := 200;
exception
when others then
apex_json.open_object;
apex_json.write('error', 'Image not found');
apex_json.write('id', v_image_id, true);
apex_json.close_object;
raise;
end;
exception
when no_data_found then
:status_code := 404;
when others then
:status_code := 500;
end;

Handler Output

When an image deletion is successful, the handler should only set HTTP status code 200.

Error handling

The plug-in display deleting error as APEX inline page notification error with message Image delete failed and message assigned to JSON error property, for example:

Image delete failed: Image not found.