如何通过控制台将图像URL存储在Firebase存储中的数据库中

时间:2019-06-20 16:28:56

标签: android firebase firebase-realtime-database

我想显示通过控制台在Firebase存储中上传的图像。有什么办法可以获取图像网址作为列表,并通过android studio将其存储在数据库中。谢谢。

直到现在尝试为止,我已经尝试将URL手动添加到arraylist并使用glide来获取图像,但是我想将图像URL存储在数据库中并从那里获取。问题是我手动存储了图像。

这是我的代码。

public class QuotesTab extends Fragment {

    private static final String TAG = "QuotesTab";
    private static final int Num_Col = 2;
    private ArrayList<String> mImages = new ArrayList<>();
    private RecyclerView mrecyclerView;
    View v;

    public QuotesTab() {
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        Log.d(TAG, "onCreateView: Preparing Recycler View");
        v = inflater.inflate(R.layout.fragment_quotes, container, false);
        mrecyclerView = v.findViewById(R.id.recycler_view_quotes);
        MyAdapter adapter = new MyAdapter(getContext(), mImages);
        StaggeredGridLayoutManager staggeredGridLayoutManager = new StaggeredGridLayoutManager(Num_Col, LinearLayoutManager.VERTICAL);
        mrecyclerView.setLayoutManager(staggeredGridLayoutManager);
        mrecyclerView.setAdapter(adapter);
        return v;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.d(TAG, "onCreate: initbitmaps");

        mImages.add("https://www.mapsofindia.com/wallpapers/tajmahal/images/taj-mahal-front-view.jpg");
        mImages.add("https://images.pexels.com/photos/2466638/pexels-photo-2466638.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500");
        mImages.add("https://images.pexels.com/photos/2406658/pexels-photo-2406658.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940");
        mImages.add("https://images.pexels.com/photos/2385210/pexels-photo-2385210.jpeg?auto=format%2Ccompress&cs=tinysrgb&dpr=2&h=650&w=940");
        mImages.add("https://images.pexels.com/photos/2462980/pexels-photo-2462980.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940");
        mImages.add("https://images.pexels.com/photos/2404365/pexels-photo-2404365.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940");
        mImages.add("https://images.pexels.com/photos/2404843/pexels-photo-2404843.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940");
        mImages.add("https://images.pexels.com/photos/2417260/pexels-photo-2417260.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940");
        mImages.add("https://images.pexels.com/photos/2407636/pexels-photo-2407636.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940");
        mImages.add("https://images.pexels.com/photos/2404055/pexels-photo-2404055.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940");
        mImages.add("https://images.pexels.com/photos/2405644/pexels-photo-2405644.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940");
        mImages.add("https://images.pexels.com/photos/2387418/pexels-photo-2387418.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940");
        mImages.add("https://images.pexels.com/photos/2407121/pexels-photo-2407121.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940");
        mImages.add("https://images.pexels.com/photos/2403014/pexels-photo-2403014.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500");
        mImages.add("https://images.pexels.com/photos/2403014/pexels-photo-2403014.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940");
        mImages.add("https://images.pexels.com/photos/2376996/pexels-photo-2376996.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940");
        mImages.add("https://images.pexels.com/photos/2440493/pexels-photo-2440493.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940");
        mImages.add("https://images.pexels.com/photos/2386587/pexels-photo-2386587.jpeg?auto=format%2Ccompress&cs=tinysrgb&dpr=2&h=650&w=940");
        mImages.add("https://images.pexels.com/photos/2404557/pexels-photo-2404557.jpeg?auto=format%2Ccompress&cs=tinysrgb&dpr=2&h=650&w=940");
        mImages.add("https://images.pexels.com/photos/2332413/pexels-photo-2332413.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940");

     }
}

我要存储图片中的图片网址

我想将图像网址存储在Firebase数据库中,然后从那里获取。

1 个答案:

答案 0 :(得分:0)

您需要在引用上使用getDownloadUrl方法。

this花费更多的时间