@@ -10,11 +10,25 @@ CLASS zcl_aws1_s3_scenario DEFINITION
1010
1111 METHODS getting_started_with_s3
1212 IMPORTING
13- !iv_bucket_name TYPE /aws1/s3_bucketname
14- !iv_key TYPE /aws1/s3_objectkey
15- !iv_copy_to_folder TYPE /aws1/s3_bucketname
13+ !iv_bucket_name TYPE /aws1/s3_bucketname
14+ !iv_key TYPE /aws1/s3_objectkey
15+ !iv_copy_to_folder TYPE /aws1/s3_bucketname
1616 EXPORTING
17- !oo_result TYPE REF TO /aws1/cl_knsputrecordoutput .
17+ !oo_result TYPE REF TO /aws1/cl_knsputrecordoutput
18+ RAISING
19+ /aws1/cx_rt_service_generic
20+ /aws1/cx_rt_technical_generic
21+ /aws1/cx_rt_no_auth_generic .
22+ METHODS presigner_get
23+ IMPORTING
24+ !iv_bucket_name TYPE /aws1/s3_bucketname
25+ !iv_key TYPE /aws1/s3_objectkey
26+ RETURNING
27+ VALUE (ov_url ) TYPE string
28+ RAISING
29+ /aws1/cx_rt_service_generic
30+ /aws1/cx_rt_technical_generic
31+ /aws1/cx_rt_no_auth_generic .
1832 PROTECTED SECTION .
1933 PRIVATE SECTION .
2034ENDCLASS .
@@ -140,4 +154,44 @@ CLASS ZCL_AWS1_S3_SCENARIO IMPLEMENTATION.
140154 "snippet-end:[s3.abapv1.getting_started_with_s3]
141155
142156 ENDMETHOD .
157+
158+
159+ METHOD presigner_get .
160+ CONSTANTS cv_pfl TYPE /aws1/rt_profile_id VALUE 'ZCODE_DEMO' .
161+
162+ "snippet-start:[s3.abapv1.s3_presigned_url_get]
163+ " iv_bucket_name is the bucket name
164+ " iv_key is the object name like "myfile.txt"
165+
166+ DATA (lo_session ) = /aws1/cl_rt_session_aws=>create( cv_pfl ).
167+ DATA (lo_s3 ) = /aws1/cl_s3_factory=>create( lo_session ).
168+
169+ "Upload a nice Hello World file to an S3 bucket."
170+ TRY .
171+ DATA (lv_contents ) = cl_abap_codepage=>convert_to( 'Hello, World' ).
172+ lo_s3->putobject(
173+ iv_bucket = iv_bucket_name
174+ iv_key = iv_key
175+ iv_body = lv_contents
176+ iv_contenttype = 'text/plain' ).
177+ MESSAGE 'Object uploaded to S3 bucket.' TYPE 'I' .
178+ CATCH /aws1/cx_s3_nosuchbucket.
179+ MESSAGE 'Bucket does not exist.' TYPE 'E' .
180+ ENDTRY .
181+
182+ " now generate a presigned URL with a 600-second expiration
183+ DATA (lo_presigner ) = lo_s3->get_presigner( iv_expires_sec = 600 ).
184+ " the presigner getobject() method has the same signature as
185+ " lo_s3->getobject(), but it doesn't actually make the call.
186+ " to the service. It just prepares a presigned URL for a future call
187+ DATA (lo_presigned_req ) = lo_presigner->getobject(
188+ iv_bucket = iv_bucket_name
189+ iv_key = iv_key ).
190+
191+ " You can provide this URL to a web page, user, email etc so they
192+ " can retrieve the file. The URL will expire in 10 minutes.
193+ ov_url = lo_presigned_req->get_url( ).
194+ "snippet-end:[s3.abapv1.s3_presigned_url_get]
195+
196+ ENDMETHOD .
143197ENDCLASS .
0 commit comments