Write file to Google Cloud Storage with Spring Boot

  Рет қаралды 17,276

CarbonRider

CarbonRider

Күн бұрын

Пікірлер: 62
@surendranathreddy9596
@surendranathreddy9596 3 жыл бұрын
Can you show how to upload images in the GCP bucket while uploading in website front end using springboot
@pratikgaikwad688
@pratikgaikwad688 3 жыл бұрын
This playlist is really clear, easy to understand and helpful, thank you @CarbonRider
@dkon8288
@dkon8288 4 жыл бұрын
Thank you. Can you show how to create folder in the bucket and then load the document into that folder ?
@CarbonRiderOnline
@CarbonRiderOnline 4 жыл бұрын
Hi @D Kon, One of the possible way is to map the google cloud storage to a VM using GCS Fuse and then make use of java file API to interact with it.
@dkon8288
@dkon8288 4 жыл бұрын
CarbonRider thank you
@manueljaramillooporto6120
@manueljaramillooporto6120 2 жыл бұрын
how can I change the metadata type? to text/csv for example, not the default application/octet-stream. THANK YOU
@CarbonRiderOnline
@CarbonRiderOnline 2 жыл бұрын
You can do that using setContentType method available on BlobInfo object.
@rjcdz06
@rjcdz06 3 жыл бұрын
Excellent! It is useful and clear! Thanks!
@torbendury4374
@torbendury4374 4 жыл бұрын
I really enjoyed your tutorial on uploading files to GC Storage, thank you! Is it also possible to upload them to a specific subdirectory in the Bucket?
@CarbonRiderOnline
@CarbonRiderOnline 4 жыл бұрын
Hi @Torben, Thanks for your words. Yes, its very much possible to upload file inside a subdirectory. You can do something like this BlobId myFileBlobId = BlobId.of("mybucket", "images/mylocalimage.jpg");
@siddharthbhandari7601
@siddharthbhandari7601 2 жыл бұрын
I do see you haven't showed authentication part, does your bucket allow anyone to upload files?
@CarbonRiderOnline
@CarbonRiderOnline 2 жыл бұрын
Hi Siddharth, Sorry, I missed to show the authentication details in this video. The bucket doesn't allow public access and it is indeed protected. The reference of the authentication JSON file was provided using following property in application.properties file spring.cloud.gcp.credentials.location=classpath:/gcp-credentials.json
@siddharthbhandari7601
@siddharthbhandari7601 2 жыл бұрын
@@CarbonRiderOnline can you please also help me to provide command to generate authentication in json format.
@CarbonRiderOnline
@CarbonRiderOnline 2 жыл бұрын
The JSON was generated using GCP cloud console itself. It was created for service account. I do have another video about that.
@siddharthbhandari7601
@siddharthbhandari7601 2 жыл бұрын
@@CarbonRiderOnline can you please share link with me
@CarbonRiderOnline
@CarbonRiderOnline 2 жыл бұрын
Here you go ----- Creating service account kzbin.info/www/bejne/Zl7GhJKnfpWLeac ---- Assign role to service account kzbin.info/www/bejne/gIGTYmyYrZhmodE
@mukhammadabdullaev9476
@mukhammadabdullaev9476 3 жыл бұрын
It's really useful! Thank you! :)
@KristinaMantha
@KristinaMantha 4 жыл бұрын
I am getting an error on storage.create(blobInfo, data); --> seems the create method does not exist in type Storage. Do you know if something has changed?
@CarbonRiderOnline
@CarbonRiderOnline 4 жыл бұрын
Kristina, The method should have worked. Please check the official documentation, it also shows and example googleapis.dev/java/google-cloud-storage/latest/com/google/cloud/storage/Storage.html#create-com.google.cloud.storage.BlobInfo-byte:A-com.google.cloud.storage.Storage.BlobTargetOption...-
@sockettofan480
@sockettofan480 3 жыл бұрын
Thanks for the tutorial...Is there way to download file of any mediatype from cloud storage using spring boot?
@CarbonRiderOnline
@CarbonRiderOnline 3 жыл бұрын
Yes, you can download any file.
@kirillknyazevknyazew1634
@kirillknyazevknyazew1634 3 ай бұрын
How can I store GCS connection variables as environment variables. It's not safe to keep JSON file.
@CarbonRiderOnline
@CarbonRiderOnline 3 ай бұрын
You shouldn't keep the JSON file inside the project source code. It can be easily be stored in Secret manager or Environment variable. If you are using docker, then you can fetch the file contents and write it to a location which can be then read by your program.
@Pedro1bc
@Pedro1bc 3 жыл бұрын
I'm getting java.nio.file.NoSuchFileException when trying to run it, even though the path is correct.
@bollywood90ssongs65
@bollywood90ssongs65 4 жыл бұрын
Can you store that file into image folder that will help us
@CarbonRiderOnline
@CarbonRiderOnline 4 жыл бұрын
It can be achieved by adding the folder name in the BlobId object being constructed. BlobId.of("bucketname", "images/myfile.txt");
@chenwang3427
@chenwang3427 3 жыл бұрын
if the application is deployed to GCP GKE and not check in your service account json with your source code, then how do you do?
@CarbonRiderOnline
@CarbonRiderOnline 3 жыл бұрын
I am note sure about GCP. But in case of AWS, there is option to assume role.
@ankitachandankar8687
@ankitachandankar8687 4 жыл бұрын
I am getting an error while running an application. Error: Project ID cannot be null or empty
@ankitachandankar8687
@ankitachandankar8687 4 жыл бұрын
Also I am getting an error while running Curl
@CarbonRiderOnline
@CarbonRiderOnline 4 жыл бұрын
What error are you getting?
@ankitachandankar8687
@ankitachandankar8687 4 жыл бұрын
@@CarbonRiderOnline Please ignore this error, it was my bad that I did not specified @RestController to my controller method.
@ankitachandankar8687
@ankitachandankar8687 4 жыл бұрын
Also, could you please upload the same videos with the use of Swagger open api spec and storing file metadata into DB .
@CarbonRiderOnline
@CarbonRiderOnline 4 жыл бұрын
@Ankita, using swagger and DB operations is a different topic.
@arifalimadina7091
@arifalimadina7091 4 жыл бұрын
It's taking time to upload image about 2-3 sec. Can we do it faster
@CarbonRiderOnline
@CarbonRiderOnline 4 жыл бұрын
The other way is to mount the GCP storage using GCSFuse utility and use java.io.* APIs to interact with the storage. That may improve the performance.
@arifalimadina7091
@arifalimadina7091 4 жыл бұрын
@@CarbonRiderOnline any reference , any blog ?
@CarbonRiderOnline
@CarbonRiderOnline 4 жыл бұрын
@Arif check this github.com/GoogleCloudPlatform/gcsfuse
@chetanchoudhary7688
@chetanchoudhary7688 3 жыл бұрын
do you have this project in git
@ankitachandankar8687
@ankitachandankar8687 4 жыл бұрын
How you configure the Default Project ID??
@CarbonRiderOnline
@CarbonRiderOnline 4 жыл бұрын
The service account json file contains reference of the project and hence you do not have to configure it.
@ankitachandankar8687
@ankitachandankar8687 4 жыл бұрын
@@CarbonRiderOnline I agree that service account json file contains the reference of the project id, but, still I was getting an error that project ID cant be Null or Empty. So what I did is, I explicitly set the ProjectID variable in my application.properties file and It started running the applicattion
@CarbonRiderOnline
@CarbonRiderOnline 4 жыл бұрын
@Ankita usually the project id is required by the services like GCP translation and not for storage. Can you paste the exception stack trace along with error message? Also which property did you configure in the application.properties?
@nikhillingam4630
@nikhillingam4630 2 жыл бұрын
Anyone knows how to write unit test for it
@CarbonRiderOnline
@CarbonRiderOnline 2 жыл бұрын
I haven't done that. But can you be more specific as what part of GCP storage that you wish to unit test?
@nikhillingam4630
@nikhillingam4630 2 жыл бұрын
@@CarbonRiderOnline file upload/fetch/delete from google storage with java
@CarbonRiderOnline
@CarbonRiderOnline 2 жыл бұрын
Is the intention to check if Google SDK APIs are working as expected? OR do you wish to check your own logic to interact with it? Ideally while writing unit test cases, you shouldn't test third party libraries (if it involves network calls or dependency on third party service).
@kousarjamadar7339
@kousarjamadar7339 3 жыл бұрын
Could you please help me to upload 1Mb file TO Bucket?
@CarbonRiderOnline
@CarbonRiderOnline 3 жыл бұрын
Yes, you can upload the file using the storage API.
@namratagove537
@namratagove537 2 жыл бұрын
I am getting Caused by: com.google.api.client.googleapis.json.GoogleJsonResponseException: 401 Unauthorized error
@CarbonRiderOnline
@CarbonRiderOnline 2 жыл бұрын
@Namrata, can you please check if you have provided required permission to the service account? If you are reading/writing content to the existing storage bucket, then you should have "Storage object creator" role assigned to the service account.
“Don’t stop the chances.”
00:44
ISSEI / いっせい
Рет қаралды 62 МЛН
Правильный подход к детям
00:18
Beatrise
Рет қаралды 11 МЛН
What is JWT? JSON Web Tokens Explained (Java Brains)
14:53
Java Brains
Рет қаралды 1 МЛН
How to Upload a File to Google Cloud Storage in Node.js
10:34
Mount Google Cloud Storage in Ubuntu
6:53
CarbonRider
Рет қаралды 3,7 М.
How to integrate Keycloak with Angular 10?
18:04
CarbonRider
Рет қаралды 37 М.
“Don’t stop the chances.”
00:44
ISSEI / いっせい
Рет қаралды 62 МЛН