I am using resumable upload api of Cloud Storage JSON API as mentioned in below code.
I have configured my credential related json in bash file GOOGLE_APPLICATION_CREDENTIALS = {json path}
When I am trying to access google API I am getting access forbidden error with 403 code.
Do I need to pass signed url in upload function?
RetryHttpInitializerWrapper class, I am not able to find so i Passed HttpRequestInitializer httpRequestInitializer = null;
I am facing some issue because of request URL only that I am sure.
InputStreamContent mediaContent = new InputStreamContent(contentType, stream);
mediaContent.setLength(mediaContent.getLength());
GoogleCredential credential = GoogleCredential.getApplicationDefault();
if (credential.createScopedRequired()) {
credential = credential.createScoped(StorageScopes.all());
}
Storage client = StorageOptions.getDefaultInstance().getService();
HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
// custom HttpRequestInitializer for automatic retry upon failures.
HttpRequestInitializer httpRequestInitializer = null;
//HttpRequestInitializer httpRequestInitializer = new RetryHttpInitializerWrapper(credential);
GenericUrl requestUrl = new GenericUrl("https://www.googleapis.com/upload/storage/v1/b/"+bucket+"/o?uploadType=resumable&name="+name);
MediaHttpUploader uploader = new MediaHttpUploader(mediaContent, httpTransport, httpRequestInitializer);
uploader.setProgressListener(new CustomProgressListener());
HttpResponse response = uploader.upload(requestUrl);
if (!response.isSuccessStatusCode()) {
throw GoogleJsonResponseException.from(JSON_FACTORY, response);
}