hi
I have oracle
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Apex 23.1.4, Schema Compatibility 2023.04.28, Patch Version4
I need to upload image and video to google bucket
This code, works good when the public bucket is configure, but when apply permission to service account, and I add on oracle web credential, I can't make it work.
Is OK this:
I download json from google, service account generated jey.
{
"type": "service_account",
"project_id": "project-name",
"private_key_id": "xxxxx",
"private_key": "xxxxx",
"client_email": "xxxxx",
"client_id": "xxxxx",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "xxxxx",
"client_x509_cert_url": "xxxxx",
"universe_domain": "googleapis.com"
}
web credentials
Authentication Type: [OAuth2 Client Credentials Flow]
OAuth Scope:
Client ID or Username: [client_email]
Client Secret or Password: [private_key]
Verify Client Secret or Password: [private_key]
Valid for URLs: [https://storage.googleapis.com/*]
DECLARE
v_blob BLOB;
v_filename VARCHAR2(400);
v_mime_type VARCHAR2(200);
v_base_url VARCHAR2(4000);
v_url VARCHAR2(4000);
v_response CLOB;
BEGIN
-- 1. Levantamos el archivo que el usuario acaba de cargar en la pantalla
SELECT
blob_content,
filename,
mime_type
INTO
v_blob,
v_filename,
v_mime_type
FROM apex_application_temp_files
WHERE name = :P1047_UPLOAD;
-- 2. URL de la API de Google Drive (Modo Multipart para enviar archivo + metadata)
/*
v_url :=
'https://storage.googleapis.com/upload/storage/v1/b/'||
'_**----MY_REPO_NAME----**_'||
'/o?uploadType=media&name='||
utl_url.escape(v_filename);
*/
-- 1. URL base (SIN query string)
v_base_url := 'https://storage.googleapis.com/upload/storage/v1/b/_**----MY_REPO_NAME----**_/o';
-- 2. Query string separado (más controlable)
v_url := v_base_url
|| '?uploadType=media'
|| '&name=' || apex_util.url_encode(v_filename);
apex_web_service.g_request_headers.delete;
apex_web_service.g_request_headers(1).name := 'Content-Type';
apex_web_service.g_request_headers(1).value := v_mime_type;
v_response :=
apex_web_service.make_rest_request(
p_url => v_url,
p_http_method => 'POST',
p_body_blob => v_blob, --,
p_credential_static_id => '_**MY_GOOGLE_SERVICE_ACCOUNT**_'
);
:P1047_response := 'HTTP='||
apex_web_service.g_status_code||
chr(10)||
substr(v_response,1,3000);
/*
raise_application_error(
-20000,
'HTTP='||
apex_web_service.g_status_code||
chr(10)||
substr(v_response,1,3000)
);
*/
EXCEPTION
WHEN OTHERS THEN
raise_application_error(
-20001,
SQLCODE || ' - ' || SQLERRM
);
END;
If anyone has a complete example on this topic and could share it, it would be appreciated.
Regards
Eduardo