python - Nodejs 脚本 fs.createReadStream 到 Python 脚本

标签 python node.js file

我需要将文件转换为可读流以通过 api 上传,有一个使用 fs.createReadStream 的 Node js 示例。任何人都可以告诉我上述声明的 python 等价物是什么?

例子

const axios = require('axios');
const fs = require('fs');
const FormData = require('form-data');

export const pinFileToIPFS = (pinataApiKey, pinataSecretApiKey) => {
    const url = `https://api.pinata.cloud/pinning/pinFileToIPFS`;

    //we gather a local file for this example, but any valid readStream source will work here.
    let data = new FormData();
    data.append('file', fs.createReadStream('./yourfile.png'));

我如何以 pythonic 方式复制上面的内容?

最佳答案

open()在 Python 中执行 fs.createReadStream()Node.JS 中执行的操作。

关于python - Nodejs 脚本 fs.createReadStream 到 Python 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58387569/

相关文章:

javascript - 将三元运算符转换为 if/else 语句

node.js - ParseServer 删除状态为 "Unregistered"的安装

python - 在python中,如何根据特定值将文件解析为列表?

c++ - 如何使用 CreateFile 在 UnBuffered 模式下在 Windows 中追加文件

vba - 如何获取工作簿文件的 "Last Saved By"属性

python opencv3.0.0-beta 'module'对象没有属性 'createBackgroundSubtractorMOG()'

python - 过滤和解析 Solar Region Summary 文件中的文本

python - 如何 shell 到本地运行的 Python 应用程序?

python - 在两个不同列表中查找相同索引号以比较值的最有效方法

javascript - Ember 模型和 SQL - 在服务器上或通过 Ember 关系连接表?