如何使用Java将图像

如何使用Java将图像

本文介绍了如何使用Java将图像/文件上传到Firebase存储?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用需要使用Java将图像/文件上传到Firebase存储并将其作为API公开的功能.我已经在angular 4打字稿中实现了此功能.但是现在我需要将此方法用作Java Rest API,以便我的对等方也可以使用相同的方法,而不必编写新的方法.那么,是否有任何API或方法将映像写入Firebase存储?

I am working in a functionality where i need to upload an Image/File to firebase storage using java and expose it as an API. I have already achieved this functionality in angular 4 typescript. But now i need this method as an Java Rest API, so that my peer can also consume the same method instead of writing a new one. So is there any API or methods to write the image to firebase storage ?

推荐答案

尝试一下:

FirebaseOptions options = FirebaseOptions.builder()
                    .setCredentials(credential)
                    .setDatabaseUrl(projectUrl)
                    .setStorageBucket("YOUR BUCKET LINK")
                    .build();

    FirebaseApp fireApp = FirebaseApp.initializeApp(options);

    StorageClient storageClient = StorageClient.getInstance(fireApp);
            InputStream testFile = new FileInputStream("YOUR FILE PATH");
            String blobString = "NEW_FOLDER/" + "FILE_NAME.EXT";

    storageClient.bucket().create(blobString, testFile , Bucket.BlobWriteOption.userProject("YOUR PROJECT ID"));

这篇关于如何使用Java将图像/文件上传到Firebase存储?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 14:08