2525import com .facebook .react .bridge .Promise ;
2626
2727import com .amazonaws .services .s3 .*;
28+ // Updated to handle special chars issue in file key name
29+ import com .amazonaws .mobile .client .AWSMobileClient ;
2830import com .amazonaws .mobileconnectors .s3 .transferutility .*;
31+
2932import com .facebook .react .bridge .ReadableMap ;
3033import com .facebook .react .bridge .ReadableMapKeySetIterator ;
3134import com .facebook .react .bridge .WritableArray ;
@@ -101,8 +104,17 @@ public void onStateChanged(int id, TransferState state) {
101104
102105 @ Override
103106 public void onProgressChanged (int id , long bytesCurrent , long bytesTotal ) {
104- System .out .println ("TASK ID:" + id );
107+ // System.out.println("TASK ID:" + id);
105108 TransferObserver task = transferUtility .getTransferById (id );
109+
110+ // Updated to handle special chars issue in file key name
111+ // Added Null Check to prevent
112+ // AndroidRuntime: java.lang.NullPointerException: Attempt to invoke
113+ // virtual method 'com.amazonaws.mobileconnectors.s3.transferutility.TransferState
114+ // com.amazonaws.mobileconnectors.s3.transferutility.TransferObserver.getState()' on a null object reference
115+ if (task == null ) {
116+ return ;
117+ }
106118 if (task .getState ().toString ().equals ("IN_PROGRESS" ) && !enabledProgress ) {
107119 return ;
108120 }
@@ -180,19 +192,9 @@ private boolean setup(Map<String, Object> credentialsOptions) {
180192 default :
181193 return false ;
182194 }
183- // TODO: TransferNetworkLossHandler
184- // TransferNetworkLossHandler.getInstance(context);
185- //TODO
186- // TransferUtility transferUtility =
187- // TransferUtility.builder()
188- // .context(context.getApplicationContext())
189- // .awsConfiguration(AWSMobileClient.getInstance().getConfiguration())
190- // .s3Client(new AmazonS3Client(AWSMobileClient.getInstance()))
191- // .build();
192-
193- // BasicAWSCredentials creds = new BasicAWSCredentials("access_key", "secret_key");
194- // AmazonS3 s3Client = AmazonS3ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(creds)).build();
195- //TODO
195+
196+ // Updated to handle special chars issue in file key name
197+ TransferNetworkLossHandler .getInstance (context );
196198
197199 // TODO: support ClientConfiguration
198200 if (credentials != null ) {
@@ -201,7 +203,14 @@ private boolean setup(Map<String, Object> credentialsOptions) {
201203 s3 = new AmazonS3Client (credentialsProvider );
202204 }
203205 s3 .setRegion (region );
204- transferUtility = new TransferUtility (s3 , context );
206+ //transferUtility = new TransferUtility(s3, context);
207+
208+ transferUtility = TransferUtility .builder ()
209+ .context (context )
210+ .awsConfiguration (AWSMobileClient .getInstance ().getConfiguration ())
211+ .s3Client (s3 )
212+ .build ();
213+
205214 return true ;
206215 }
207216
0 commit comments