简体   繁体   English

我可以在我的反应应用程序中搜索存储在谷歌存储桶中的一些文件吗?

[英]Can i search about some files stored in google bucket inside my react app?

I have a reaction app that stores some files in the google cloud " Bucket " so I wonder if I can search for some files stored in a 'Bucket' inside my React app which i don't know what is the exact name of it, Can I do that?我有一个反应应用程序,它将一些文件存储在谷歌云“Bucket”中,所以我想知道是否可以搜索存储在我的 React 应用程序内的“Bucket”中的一些文件,我不知道它的确切名称是什么,我可以这样做吗? If yes, in what way?如果是,以什么方式? if you have any tutorial, i will be appreciate.如果您有任何教程,我将不胜感激。

What i mean by search is this list and filter:我所说的搜索是这个列表和过滤器:

在此处输入图像描述 thanks in advance.提前致谢。

What do you mean "search"? “搜索”是什么意思? If you already know the name you want to find, you can try to open the file.如果您已经知道要查找的名称,可以尝试打开该文件。 If it fails, it either doesn't exist or you don't have permission to open it.如果失败,它要么不存在,要么您无权打开它。

If you want to see if it exists before opening, this should point you in the right direction:如果您想在打开之前查看它是否存在,这应该为您指明正确的方向:

from google.cloud import storage
client = storage.Client()

blobs = client.list_blobs('your_default_bucket')

filenames = []
for blob in blobs:
    filenames.append(blob.name)
    
print(filenames)

file_exists = 'my_file.csv' in filenames

print(f"file_exists: {file_exists}")

For this kind of cases it's better to use 3rd part libraries.对于这种情况,最好使用第三部分库。 One that could suit your need is react-autosuggest .一个可以满足您需要的是react-autosuggest

basic usage:基本用法:

import Autosuggest from 'react-autosuggest';
 
// Imagine you have a list of languages that you'd like to autosuggest.
const files = [
  {
    name: 'file1'
  },
  {
    name: 'file2'
  },
  ...
];
 
// Teach Autosuggest how to calculate suggestions for any given input value.
const getSuggestions = value => {
  const inputValue = value.trim().toLowerCase();
  const inputLength = inputValue.length;
 
  return inputLength === 0 ? [] : languages.filter(lang =>
    lang.name.toLowerCase().slice(0, inputLength) === inputValue
  );
};
 
// When suggestion is clicked, Autosuggest needs to populate the input
// based on the clicked suggestion. Teach Autosuggest how to calculate the
// input value for every given suggestion.
const getSuggestionValue = suggestion => suggestion.name;
 
// Use your imagination to render suggestions.
const renderSuggestion = suggestion => (
  <div>
    {suggestion.name}
  </div>
);
 
class Example extends React.Component {
  constructor() {
    super();
 
    // Autosuggest is a controlled component.
    // This means that you need to provide an input value
    // and an onChange handler that updates this value (see below).
    // Suggestions also need to be provided to the Autosuggest,
    // and they are initially empty because the Autosuggest is closed.
    this.state = {
      value: '',
      suggestions: []
    };
  }
 
  onChange = (event, { newValue }) => {
    this.setState({
      value: newValue
    });
  };
 
  // Autosuggest will call this function every time you need to update suggestions.
  // You already implemented this logic above, so just use it.
  onSuggestionsFetchRequested = ({ value }) => {
    this.setState({
      suggestions: getSuggestions(value)
    });
  };
 
  // Autosuggest will call this function every time you need to clear suggestions.
  onSuggestionsClearRequested = () => {
    this.setState({
      suggestions: []
    });
  };
 
  render() {
    const { value, suggestions } = this.state;
 
    // Autosuggest will pass through all these props to the input.
    const inputProps = {
      placeholder: 'Type a programming language',
      value,
      onChange: this.onChange
    };
 
    // Finally, render it!
    return (
      <Autosuggest
        suggestions={suggestions}
        onSuggestionsFetchRequested={this.onSuggestionsFetchRequested}
        onSuggestionsClearRequested={this.onSuggestionsClearRequested}
        getSuggestionValue={getSuggestionValue}
        renderSuggestion={renderSuggestion}
        inputProps={inputProps}
      />
    );
  }
}

check a demo here also也在这里查看演示

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法从Google App Engine内部构建React应用 - Can't build React app from inside Google App Engine 如何从我的 React 应用程序远程执行 Google Compute Instance 中的终端脚本/命令? - How can I execute terminal script/command in Google Compute Instance remotely from my React app? 将一些图像手动存储在 firebase 存储中并在我的反应原生应用程序中使用它 - take some images stored manualy in firebase storage and use it in my react native app 如何为我的 react-native 应用程序提供谷歌登录? - How can I provide my react-native app with google sign in? 为什么我无法在 google、yahoo 和 bing 搜索中索引我的 react-app? - Why I can't index my react-app on google,yahoo and bing searches? 如何在不覆盖我的 CSS 文件的情况下将本地 Bootstrap CSS 导入 React 应用程序? - How can I import local Bootstrap CSS into a React app without overriding my CSS files? (反应)当我从 API 获取一些数据时,如何阻止我的 web 应用程序重新渲染? - (React) How can I stop my web app from re-rendering when I fetch some data from an API? 我可以阻止在React App中在服务器端呈现某些路由 - Can I prevent some route to be rendered on server side in React App 无法在Google Compute Engine上访问我的React App - Can't access my React App on Google Compute Engine 对我的反应应用程序中的这个编译器错误感到困惑 - Confused about this compiler error in my react app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM