Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
622 views
in Technique[技术] by (71.8m points)

Uploading images to Firebase with Spring boot

Hello everyone I'm currently working on the submission of images on firebase storage from my spring boot api, currently everything works I can submit my images but the public url of the image is not available, I would like to know how to get a public url of my image from my api

public void uploadFile(MultipartFile multipartFile, String path) throws IOException {
    String objectName = generateFileName(multipartFile);
    StorageOptions storageOptions = StorageOptions.newBuilder()
            .setProjectId("my-project")
            .setCredentials(GoogleCredentials
                    .fromStream(new ClassPathResource("firebase_admin.json").getInputStream()))
            .build();
    Storage storage = storageOptions.getService();
    BlobId blobId = BlobId.of("bucket-name", objectName);

    BlobInfo blobInfo = BlobInfo.newBuilder(blobId).setContentType(multipartFile.getContentType()).build();

    Blob blob = storage.create(blobInfo, multipartFile.getBytes());

    System.out.println("UPLOAD FILE" + multipartFile.getName() + " " + multipartFile.getSize() + " octet");


}
question from:https://stackoverflow.com/questions/65856812/uploading-images-to-firebase-with-spring-boot

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If the image is public, here the URL pattern

https://storage.cloud.google.com/<bucket-name>/<objectName>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...