I’ve written up a document showing how to upload Media Library images to IFS Cloud using Rest calls (Postman)
Thanks, Paul, this is much appreciated!
Is there a current solution in IFS Cloud to upload large set of media items?
If not can this Postman method be utilized for this?
Thanks in advance!
Harsha
Hi
I think uploading with PLSQL going to be easy. You can get references from blocks in the below.
Upload
/*CREATE OR REPLACE DIRECTORY TEMP_DIR7 AS 'C:\TEMP_DIR7';
GRANT READ, WRITE ON DIRECTORY temp_dir TO PUBLIC;
SELECT * FROM DBA_DIRECTORIES;*/
DECLARE
user_id_ VARCHAR2(100) :='A1';
file_name_ VARCHAR2(32767) := '1.jpg';
picture_blob_ BLOB;
picture_bfile_ BFILE;
fileopen_failed_exc_ EXCEPTION;
PRAGMA EXCEPTION_INIT (fileopen_failed_exc_, -22288);
info_ VARCHAR2(32767);
objid_ VARCHAR2(32767);
objversion_ VARCHAR2(32767);
attr_ VARCHAR2(32767);
blob_id_ binary_object.blob_id%TYPE;
dest_offset_ NUMBER := 1;
src_offset_ NUMBER := 1;
BEGIN
language_sys.set_language('en');
picture_bfile_ := BFILENAME('TEMP_DIR', file_name_); --CREATE OR REPLACE DIRECTORY TEMP_DIR AS 'C:\TEMP_DIR'; serverda C altına manule oluşturmak lazım. Değişken gibi oluşturuyor.
BEGIN
dbms_lob.fileopen(picture_bfile_, dbms_lob.file_readonly);
dbms_lob.createtemporary(picture_blob_, TRUE);
dbms_lob.loadblobfromfile (
dest_lob => picture_blob_,
src_bfile => picture_bfile_,
amount => dbms_lob.lobmaxsize,
dest_offset => dest_offset_,
src_offset => src_offset_);
dbms_lob.fileclose(picture_bfile_);
EXCEPTION WHEN fileopen_failed_exc_ THEN
picture_blob_ := NULL;
dbms_lob.fileclose(picture_bfile_);
END;
SELECT picture_id
INTO blob_id_
FROM person_info
WHERE person_id = UPPER(user_id_);
binary_object_api.create_or_replace(
blob_id_ => blob_id_,
display_text_ => file_name_,
file_name_ => file_name_,
file_path_ => 'C:\ds\',
external_storage_ => 'FALSE',
length_ => 0,
type_ => 'PICTURE',
application_data_ => '');
binary_object_data_block_api.new__(
objversion_ => objversion_,
objid_ => objid_,
blob_id_ => blob_id_,
application_data_ => '7');
binary_object_data_block_api.write_data__(
objversion_ => objversion_,
rowid_ => objid_,
lob_loc_ => picture_blob_);
SELECT objid,
objversion
INTO objid_,
objversion_
FROM person_info
WHERE person_id = UPPER(user_id_);
client_sys.clear_attr(attr_);
client_sys.add_to_attr('PICTURE_ID', blob_id_, attr_);
person_info_api.modify__(info_, objid_, objversion_, attr_, 'DO');
END;
Download
CREATE OR REPLACE DIRECTORY TEMP_DIR AS 'C:\TEMP_DIR';
GRANT READ, WRITE ON DIRECTORY TEMP_DIR TO PUBLIC;
SELECT * FROM DBA_DIRECTORIES;
DECLARE
temp_ INTEGER;
PROCEDURE download_picture
(
picture_id_ IN INTEGER,
pic_name_ IN VARCHAR2,
folder_name_ IN VARCHAR2
) IS
l_file utl_file.file_type;
l_buffer RAW(32767);
l_amount BINARY_INTEGER := 32767;
l_pos INTEGER := 1;
l_blob BLOB;
l_blob_len INTEGER;
l_filename VARCHAR2(256);
BEGIN
SELECT b.data INTO l_blob FROM ifsapp.binary_object_data_block b WHERE b.blob_id = picture_id_;
l_filename := pic_name_ || '.jpg';
l_blob_len := dbms_lob.getlength(l_blob);
l_file := utl_file.fopen(folder_name_, l_filename, 'wb');
WHILE l_pos < l_blob_len
LOOP
dbms_lob.read(l_blob, l_amount, l_pos, l_buffer);
utl_file.put_raw(l_file, l_buffer, TRUE);
l_pos := l_pos + l_amount;
END LOOP;
utl_file.fclose(l_file);
END download_picture;
BEGIN
FOR rec_ IN (SELECT t.picture_id,
t.emp_no
FROM ifsapp.company_person t
WHERE t.picture_id IS NOT NULL)
LOOP
BEGIN
SELECT b.blob_id INTO temp_ FROM ifsapp.binary_object_data_block b WHERE b.blob_id = rec_.picture_id;
EXCEPTION
WHEN no_data_found THEN
CONTINUE;
END;
download_picture(rec_.picture_id, rec_.emp_no, 'TEMP_DIR');
END LOOP;
END;
Is there a current solution in IFS Cloud to upload large set of media items?
If not can this Postman method be utilized for this?
Thanks in advance!
Harsha
We don't have any way to upload media items in bulk. You need to use Postman or some other REST-capable tool. You should even be able to use the command line tool "curl" that's readily available on different operating systems. Or ask ChatGPT to write a program in any favorite language
Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.